SQL 查询更新然后恢复更改
我目前对一个问题感到困惑。我可以在表中插入和删除记录,但无法更新某些字段。它确实会暂时更新它,然后在 0.5 秒后恢复更改,我实际看到了更改。顺便说一句,这是在 Delphi 7 中完成的:
CloseDatabase; // Closes my database first to prevent an error from accessing one that is already open
OpenDatabase; // Dynamically opens the database
ActivateEdits;
if dbeEnglish.Enabled then
begin
qryDictionary.SQL.Text := 'Update [word list] set [english] = "'+dbeEnglish.Text+'" where ([afrikaans] = "'+dbeAfrikaans.Text+'") and ([english] = "'+sEnglishBefore+'")';
qryDictionary.ExecSQL;
end
else
begin
qryDictionary.SQL.Text := 'Update [word list] set [afrikaans] = "'+dbeAfrikaans.Text+'" where ([english] = "'+dbeEnglish.Text+'") and ([afrikaans] = "'+sAfrikaansBefore+'")';
qryDictionary.ExecSQL;
end;
SelectAll; // SQL to select * from [word list] as well as set the column widths
bEngOnce := False; // variable i used to prevent both dbe (data base edits) from being edited
bAfrOnce := False;
我是否更新了 OI 中的错误或丢失的内容?它确实更新了,但并没有使其永久化。
忘记提及:表单词列表有 3 个字段:一个称为 ID、英语和南非荷兰语的自动编号字段。自动编号是否会导致更新问题?
I'm currently baffled by the one problem. I can insert and delete records from my table but I can't update certain fields. It does update it temporarily before reverting changes 0.5 seconds later, I physically see the change. Btw this is done in Delphi 7:
CloseDatabase; // Closes my database first to prevent an error from accessing one that is already open
OpenDatabase; // Dynamically opens the database
ActivateEdits;
if dbeEnglish.Enabled then
begin
qryDictionary.SQL.Text := 'Update [word list] set [english] = "'+dbeEnglish.Text+'" where ([afrikaans] = "'+dbeAfrikaans.Text+'") and ([english] = "'+sEnglishBefore+'")';
qryDictionary.ExecSQL;
end
else
begin
qryDictionary.SQL.Text := 'Update [word list] set [afrikaans] = "'+dbeAfrikaans.Text+'" where ([english] = "'+dbeEnglish.Text+'") and ([afrikaans] = "'+sAfrikaansBefore+'")';
qryDictionary.ExecSQL;
end;
SelectAll; // SQL to select * from [word list] as well as set the column widths
bEngOnce := False; // variable i used to prevent both dbe (data base edits) from being edited
bAfrOnce := False;
Am I updating wrong or missing something in OI? It does update just doesn't make it permanent.
Forgot to mention: The table word list has 3 fields: an auto number field called ID, english and afrikaans. Could the auto number be causing a problem to update?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会尝试以下方法。我不确定它是否有帮助,但你可以检查 ExecSQL 结果。巴拉特似乎提到您的代码中有未提交的事务。
您还可以检查某些行是否会受到提交的影响。这是由 TADOQuery.ExecSQL 函数结果返回的,因此您可以通过这种方式进行检查。
I would try the following. I'm not sure if it helps but you can check the ExecSQL result. It seems as Bharat mentioned that you have uncommited transaction in your code.
You can also check if some of the rows will be affected by a commit. This is returned by TADOQuery.ExecSQL function result, so you can check it this way.