TADOQuery.Open 执行一条语句,但仅执行一次

发布于 2024-10-01 15:02:19 字数 499 浏览 0 评论 0原文

我使用此代码将行从 Table1 复制到 Table2,但它给了我

命令文本不返回结果集

 ADOQuery1.Close;
 ADOQuery1.SQL.Clear;
 ADOQuery1.SQL.Add('insert into Table1');
 ADOQuery1.SQL.Add('select Field1 ,Field2 from Table2');
 ADOQuery1.SQL.Add('where ArtNo= 1');
 ADOQuery1.Open;
 ADOQuery1.Refresh ;

如果我不使用

 ADOQuery1.Open;

它给我

ADOQuery1:无法对封闭数据集执行此操作。

它复制了我想要的内容,但只复制了一次。如何复制多次?谢谢。

I use this code to copy row from Table1 to Table2, but it gives me

Command Text does not return a result set

 ADOQuery1.Close;
 ADOQuery1.SQL.Clear;
 ADOQuery1.SQL.Add('insert into Table1');
 ADOQuery1.SQL.Add('select Field1 ,Field2 from Table2');
 ADOQuery1.SQL.Add('where ArtNo= 1');
 ADOQuery1.Open;
 ADOQuery1.Refresh ;

If I don't use

 ADOQuery1.Open;

it gives me

ADOQuery1: Cannot perform this operation on a closed dataset.

It copies what I want but only once. How to copy many times? Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一笔一画续写前缘 2024-10-08 15:02:19

对于不打开游标的脚本(例如插入、更新或执行脚本),请使用 TADOQuery 的 ExecSQL 方法。

它返回一个整数,表示查询影响的行数。

ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('insert into Table1');
ADOQuery1.SQL.Add('select Field1 ,Field2 from Table2');
ADOQuery1.SQL.Add('where ArtNo= 1');
NumRows := ADOQuery1.ExecSQL;
ShowMessageFmt('Affected rows on Table2: %d', [NumRows]);

For scripts that do not open a cursor (like insert, update or exec ones) use the ExecSQL Method of TADOQuery.

It returns a Integer representing the number of affected rows by your query.

ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('insert into Table1');
ADOQuery1.SQL.Add('select Field1 ,Field2 from Table2');
ADOQuery1.SQL.Add('where ArtNo= 1');
NumRows := ADOQuery1.ExecSQL;
ShowMessageFmt('Affected rows on Table2: %d', [NumRows]);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文