使用Delphi和SQL Server的ADO无法识别数据库更改 [英] Database change not recognized by ADO using Delphi and SQL Server

查看:151
本文介绍了使用Delphi和SQL Server的ADO无法识别数据库更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用2个 TADOConnection 运行一个小型数据库应用程序到我的SQL Server。第一个连接仅使用 ADOTable Datasource DBNavigator
使用以下代码在运行时创建第二个连接

I run a small db application with 2 TADOConnection to my SQL Server. The first connection is just for viewing purpose using ADOTable, Datasource and DBNavigator. The second connection is created at run time using the following code

aConnection:=TADOConnection.create(nil);

aTable:= TADOTable.create(nil);
aConnection.LoginPrompt := false;

.....
aTable.Edit;

aTable.Insert;

aTable.FieldByName(' ... ').AsInteger :=  .... ;

aTable.FieldByName(' .... ').AsString :=  ... ;

aTable.FieldByName(' .... ').AsString :=  ..... ;

aTable.Post;

aTable.active := false;

aConnection.connected :=false;

aTable.free;

aConnection.free;

如果使用此代码插入记录,则按更新导航器时看不到更改的数据按钮。我需要重新启动应用程序才能查看所有新插入的数据。
为什么第一个dbconnection无法识别更改使我成为第二个连接?

If I insert records with this code I can't see the changed data if I press the Update Navigator button. I need to restart my application to see all my new inserted data. Why is the first dbconnection not recognizing the changes made my the second connection ?

推荐答案

如果我退伍了,请尝试一下正确的是,较旧的Delphi / Adoverions中存在一个问题,当重新查询正常时,刷新无法按预期工作。

Try this, if I rember correct there was an issue in older Delphi/Adoverions with refresh not working as expected while requery did fine.

procedure TForm2.DBNavigator1Click(Sender: TObject; Button: TNavigateBtn);
begin
  if Button = nbRefresh then
  BEGIN
    if Assigned(TDBNavigator(Sender).DataSource) then
      if Assigned(TDBNavigator(Sender).DataSource.DataSet) then
        if TDBNavigator(Sender).DataSource.DataSet is TCustomAdoDataset then
          TADODataSet(TDBNavigator(Sender).DataSource.DataSet).Requery;
  END;
end;

这篇关于使用Delphi和SQL Server的ADO无法识别数据库更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆