在Dbgrid 中直接修改,追加ms sql 表中的记录时,为何显示不正常?(50分)

Y

yifawu

Unregistered / Unconfirmed
GUEST, unregistred user!
在Dbgrid 中直接修改,追加ms sql 表中的记录时,当按下向下光标移动
键追加记录时,则先前追加的记录就不显示了。
我试图给表增加 identity primary key 属性的字段,
并将indexfield 指向该字段, 但仍然如此,为什么?

 
当按下向下光标键时刚才的记录有时显示两行,为什么?
 
第一个问题无法解决,Delphi就是如此,你只能使用cachedupdates,
即将query的cachedupdates设为true.或者先close 后open.

第二个问题你可以看一下query的unidirectional是否被设为true了,应为false
 
这个问题我也是经常碰到,把Ttable的AfterPost事件为:
procedure TForm1.ApplyButtonClick(Sender: TObject);

begin
with table1 do
begin
Database1.StartTransaction;
try
ApplyUpdates; {try to write the updates to the database};
Database1.Commit; {on success, commit the changes};
except
Database1.Rollback; {on failure, undo the changes};
raise; {raise the exception to prevent a call to CommitUpdates!}
end;
CommitUpdates; {on success, clear the cache}
end;

Database1为Tdatabase1,table1的Cachedupdate=true。
再试一试,应该没有问题了。
 
该问题最近我也遇到过,我的解决方法如下:
1 定义MSSQL表时必须指定关键字段。
2 若不将query的cachedupdates设为true,而直接操作数据,应将Table之AutoRefresh置为True.
 
如果你设置过滤条件的话,
当你添加的记录不在条件中,
追加的记录就会被过滤掉。
 
我在每次插入记录后,用refresh语句一次,可解决此问题。
 
顶部