关于相同结构的数据表之间问题。

cpilq 2004-11-21 01:05:30
with MainDm.DataModule1 do
begin
ADOQuery2.Close;
ADOQuery2.SQL.Clear;
ADOQuery2.SQL.Text := 'select * from RentInfo where RentEndDate = Format(Date(), "yyyy-mm-dd")';
ADOQuery2.Open;
qryrentinfo1.Close;
qryrentinfo1.SQL.Clear;
qryrentinfo1.SQL.Text := 'select * from RentInfo where FKMemo <> ''一次结清'' and TraceDate = Format(Date(), "yyyy-mm-dd")';
qryrentinfo1.Open;
qrytxb1.Close;
qrytxb1.SQL.Clear;
qrytxb1.SQL.Text := 'select * from txb';
qrytxb1.Open;
if not qryrentinfo1.Eof then
begin
//假如rentinfo有适合的数据,判断表中数据是否与txb表中的数据相同。相同去除,不同取出。
if not qrytxb1.Eof then
begin
while not qrytxb1.Eof do
begin
qrytxb1.First;
if qrytxb1.FieldValues['recid'] = qryrentinfo1.FieldValues['recid'] then
begin
qrytxb1.Delete;
end;
qrytxb1.Next;
end;
ADOQuery3.Close;
ADOQuery3.SQL.Clear;
ADOQuery3.SQL.Text := 'insert into TXB select * from RentInfo where FKMemo <> ''一次结清'' and TraceDate = Format(Date(), "yyyy-mm-dd")';
ADOQuery3.Open;
end
else
begin
ADOQuery3.Close;
ADOQuery3.SQL.Clear;
ADOQuery3.SQL.Text := 'insert into TXB select * from RentInfo where FKMemo <> ''一次结清'' and TraceDate = Format(Date(), "yyyy-mm-dd")';
ADOQuery3.Open;
end;
end
else
begin
if not qrytxb1.Eof then
begin
Self.suiDBGrid3.DataSource := dstxb1;
end
else
begin
Self.suiDBGrid3.Hide;
end;
end;
end;


这个是关于两个结构相同的数据表的问题。A表查询出条件符合的数据出来之后,写入B表中。在写入之前要先进行判断。是否相同或者是为空。如果B表为空,那么就理所当然的可以直接写入B表。如果相同。那么就将B表中,相同的数据删除。循环的将相同的部分数据删除干净。然后将剩下的不同的数据写入B表。现在这个问题是我现在A表中有两条数据是符合条件的。B表是两条相同的数据,本来循环删除之后,在写入,应该是同样的两条数据。但是发现运行程序之后只剩下一条数据。这个究竟是什么问题。清哥们帮忙。
...全文
128 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
bee2518 2004-11-22
  • 打赏
  • 举报
回复
qrytxb1.First;//放在前面,不然每次循环都在第一条
while not qrytxb1.Eof do
begin
//qrytxb1.First;
if qrytxb1.FieldValues['recid'] = qryrentinfo1.FieldValues['recid'] then
begin
qrytxb1.Delete;
end
else
qrytxb1.Next;//delete后自己跳到下一条
end;
qizhanfeng 2004-11-22
  • 打赏
  • 举报
回复
delete不用Next
qrytxb1.Next;//去掉
Changefish 2004-11-22
  • 打赏
  • 举报
回复
begin
qrytxb1.Delete;
end;
qrytxb1.Next; //删除

delete就不用Next了 本省delete后会跳到下一条
zwb666 2004-11-21
  • 打赏
  • 举报
回复
学习
zhlwyy 2004-11-21
  • 打赏
  • 举报
回复
while not qrytxb1.Eof do
begin
qrytxb1.First;
if qrytxb1.FieldValues['recid'] = qryrentinfo1.FieldValues['recid'] then
begin
qrytxb1.Delete;
end;
qrytxb1.Next;
end;




-----------------
qrytxb1.First;
while not qrytxb1.Eof do
begin
if qrytxb1.FieldValues['recid'] = qryrentinfo1.FieldValues['recid'] then
begin
qrytxb1.Delete;
qrytxb1.Next;
end;
end;

2,496

社区成员

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

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