ADO 数据库应用问题

cousin_2245 2013-06-06 10:50:31
楼主好!问题是这样的,

我在form1里添加了一个ADOTable1、一个ADOQuery1、一个DataSource1和一个DBGrid。

数据库是Access的mdb数据库,数据库有两个表(账单表、账单明细表)和一个查询(根据两个表连接得来)query1。

设置ADOTable1的table name属性为查询query1.
设置DataSource1的DataSet属性为ADOTable1;
DBGrid的datasource属性设为DataSource1

ADOQuery1的sql语句为在账单明细表里添加一记录。

问题是我通过ADOQuery1往账单明细表里添加记录后运行ADOTable1->ReQuery();,DBGrid并不显示新记录。
用ADOTable1->Active=false;ADOTable1->Active=true;替换ADOTable1->ReQuery();也不行。

但是我另外加了一个TButton1,利用TButton1去运行ADOTable1->ReQuery();DBGrid却可以显示新记录。

后来我又做了一个测试,我通过ADOQuery1往账单明细表里添加记录后,马上点TButton1(时间控制在1-2秒内)刷新记录,结果是DBGrid没有显示新记录。

哪位高手给解释下什么原因?或有什么解决办法?

感激不尽!!!!!!
...全文
560 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
xjq2003 2013-10-24
  • 打赏
  • 举报
回复
问题应该是解决了吧,我就不多说了 好好学习,天天向上
fbmsyu 2013-09-09
  • 打赏
  • 举报
回复
11楼好,我专门来说这句话。
nextseconds 2013-09-03
  • 打赏
  • 举报
回复
引用 1 楼 sololie 的回复:
鄙视头3个字 看help说明 Call Requery to refresh the recordset. Requery updates the dataset by re-executing the original command or SQL statement that produced the recordset. The effects of Requery are the same as calling the dataset抯 Close method and then its Open method. However, there are circumstances when one means of refreshing the recordset is better than the other. The values in properties like CursorLocation, CursorType, and LockType cannot be changed while the dataset is open, so Requery can only refresh the recordset using the existing values in these properties. To refresh the recordset using different values for these properties, effect the refresh using the Close and Open methods. Options is a TExecuteOptions value that specifies the characteristics of the command execution affected by the requery that produces the recordset for the dataset. 你有改过CursorLocation,CursorType,LockType 这些属性么?
同意观点。设置一下属性
宝龙哥 2013-06-14
  • 打赏
  • 举报
回复
解决这一问题蜷在ADOConnection控件上了,用它可以避免所有延迟不管如何用ADOTable还是ADOQuery都不会有延迟,并且避免了这些控件逐个设置数据库连接的麻烦
scoredhigh 2013-06-13
  • 打赏
  • 举报
回复
8楼好!楼上已经说了很多了, 用ADOQuery吧
宝龙哥 2013-06-10
  • 打赏
  • 举报
回复
你需要使用一个ADOConnection控件,ADOQuery和ADOTable通过它来和数据库连接,否则的话会有延迟,除非同一个控件实现刷新,比如: ADOTable1->Insert(); 和 ADOTable1->Append(); 插入的数据就不需要刷新了
路过路人乙 2013-06-10
  • 打赏
  • 举报
回复
6楼好. 同5L建议.使用adoquery.adotable真心不好用.. 关于刷新可以利用先Close然后Open.必定能刷新.如果要定位到刷新前的那条记录就使用ReNo.
cousin_2245 2013-06-09
  • 打赏
  • 举报
回复
没人遇到过这些问题么?? 自己顶一下。。
缘中人 2013-06-09
  • 打赏
  • 举报
回复
5楼好! 你干脆放个adoquery,写个查询sql语句。 一个query负责保存数据,另外一个query负责查询数据,不会有问题的,也不会有延迟
cousin_2245 2013-06-07
  • 打赏
  • 举报
回复
Call Requery to refresh the recordset. Requery updates the dataset by re-executing the original command or SQL statement that produced the recordset. 按说明上的解释是这个意思啊,但为什么这一秒添加了记录,要隔2,3秒才能查到呢?
cousin_2245 2013-06-07
  • 打赏
  • 举报
回复
引用 1 楼 sololie 的回复:
鄙视头3个字 看help说明 Call Requery to refresh the recordset. Requery updates the dataset by re-executing the original command or SQL statement that produced the recordset. The effects of Requery are the same as calling the dataset抯 Close method and then its Open method. However, there are circumstances when one means of refreshing the recordset is better than the other. The values in properties like CursorLocation, CursorType, and LockType cannot be changed while the dataset is open, so Requery can only refresh the recordset using the existing values in these properties. To refresh the recordset using different values for these properties, effect the refresh using the Close and Open methods. Options is a TExecuteOptions value that specifies the characteristics of the command execution affected by the requery that produces the recordset for the dataset. 你有改过CursorLocation,CursorType,LockType 这些属性么?
除了以上说的,没有改过任何属性,都是默认的。
sololie 2013-06-06
  • 打赏
  • 举报
回复
鄙视头3个字 看help说明 Call Requery to refresh the recordset. Requery updates the dataset by re-executing the original command or SQL statement that produced the recordset. The effects of Requery are the same as calling the dataset抯 Close method and then its Open method. However, there are circumstances when one means of refreshing the recordset is better than the other. The values in properties like CursorLocation, CursorType, and LockType cannot be changed while the dataset is open, so Requery can only refresh the recordset using the existing values in these properties. To refresh the recordset using different values for these properties, effect the refresh using the Close and Open methods. Options is a TExecuteOptions value that specifies the characteristics of the command execution affected by the requery that produces the recordset for the dataset. 你有改过CursorLocation,CursorType,LockType 这些属性么?

1,178

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 数据库及相关技术
社区管理员
  • 数据库及相关技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧