delphi Ado(mdb)更新记录
我正在尝试从一个主表和另外 2 个子表复制数据。当我在主表中选择一条记录时,我会将该表中的所有字段复制到另一条记录中。 (Table1从ADOQuery复制所选记录)
procedure TForm1.copyButton7Click(Sender: TObject);
SQL.Clear;
SQL.Add('SELECT * from ADoquery');
SQL.Add('Where numeracao LIKE ''%'+NInterv.text);// locate record selected in Table1 NInterv.text)
Open;
// iniciate copy of record´s
begin
while not tableADoquery.Eof do
begin
Table1.Last;
Table1.Append;// how to append if necessary!!!!!!!!!!
Table1.Edit;
Table1.FieldByName('C').Value := ADoquery.FieldByName('C').Value;
Table1.FieldByName('client').Value := ADoquery.FieldByName('client').Value;
Table1.FieldByName('Cnpj_cpf').Value := ADoquery.FieldByName('Cnpj_cpf').Value;
table1.Post;
table2.next;///
end;
end;
//我如何同时从TableChield_1和TableChield_2字段更新TableChield,TableChield1?
对子表执行同样的操作 TableChield <= TableChield_1
TableChield1 <= TableChield_2
谢谢
I´m trying to copy data from one master table and 2 more child tables. When I select one record in the master table I copy all the fields from that table for the other. (Table1 copy from ADOQuery the selected record)
procedure TForm1.copyButton7Click(Sender: TObject);
SQL.Clear;
SQL.Add('SELECT * from ADoquery');
SQL.Add('Where numeracao LIKE ''%'+NInterv.text);// locate record selected in Table1 NInterv.text)
Open;
// iniciate copy of record´s
begin
while not tableADoquery.Eof do
begin
Table1.Last;
Table1.Append;// how to append if necessary!!!!!!!!!!
Table1.Edit;
Table1.FieldByName('C').Value := ADoquery.FieldByName('C').Value;
Table1.FieldByName('client').Value := ADoquery.FieldByName('client').Value;
Table1.FieldByName('Cnpj_cpf').Value := ADoquery.FieldByName('Cnpj_cpf').Value;
table1.Post;
table2.next;///
end;
end;
//How can i update the TableChield,TableChield1 from TableChield_1 and TableChield_2 fields at the same time?
do the same for the child tables
TableChield <= TableChield_1
TableChield1 <= TableChield_2
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这些字段将同时更新。实际更新是在您调用 post 时执行的(或者甚至不执行,这取决于批量更新是否打开)。
但请重新考虑一下你的逻辑。使用 SQL 语句 (INSERT) 将数据插入到另一个表中会更有效,
然后只需在循环中填充值即可。
如果数据已经位于目标表中,您还可以执行更新 - 插入模式。
像这样:
并且表明您正在将数据从表 1 复制到表 2 可能是设计缺陷的迹象。但在不了解更多情况的情况下,我不能肯定地说。无论如何,数据重复从来都不是好事。
The fields will all be updated at the same time. The actual update is performed when you call post (or not even then, it depends if the Batch Updates are on or off).
But please reconsider your logic. It would be far more efficient to use SQL statements (INSERT) in order to insert the data to the other table
Then just fill the values in a loop.
You can also do the Updade - Insert pattern if the data can alredy be in the target table.
Like This:
And also the indication that you are copying data from table 1 to table 2 could be a sign of design flaw. But I can't say that for sure without knowing more. Anyway data duplication is never good.
我相信提问者正在考虑数据完整性,这意味着,确保只有所有表都会更新或没有......
我知道安全地实现这一点的方法是使用 SQL 命令执行所有这些更新(或插入,aso)在过渡内。
I believe the asker was thinking about the data integrity, that means, ensure that only all the tables will updated or none...
The way I know to achieve this with security is executing all this updates (or inserts, a.s.o.) using SQL commands inside a transition.