var
abc:string;
procedure TForm1.Button1Click(Sender: TObject);
begin adotable2.First;
while not adotable2.Eof do
begin
abc:=adotable1.Fields[0].Value;
adoquery1.Active:=false;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from away where name=abc');
adoquery1.Active:=true;
if adoquery1.Eof=true
then
begin
adotable2.Edit;
adotable2.Delete;
end; end;end;
abc:string;
procedure TForm1.Button1Click(Sender: TObject);
begin adotable2.First;
while not adotable2.Eof do
begin
abc:=adotable1.Fields[0].Value;
adoquery1.Active:=false;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from away where name=abc');
adoquery1.Active:=true;
if adoquery1.Eof=true
then
begin
adotable2.Edit;
adotable2.Delete;
end; end;end;
解决方案 »
- UniDAC控件如何调用有输入输出参数并返回结果集的Oracle过程
- Rxrichedit怎么设置行距,字距
- 为什么我的程序在关闭的确认对话框里,按确定没反应,反而按取消关闭?
- delphi中对象无法链接和end后面的分号
- Delphi中 ADOTable控件中关于字段计算的问题
- 有关jpg加入数据的问题
- 听说Delphi7在开发信息系统方面不怎么好还有听说Borland公司现在正走下坡路这对Delphi程序员有什么影响????????
- 怎么样在添加记录给一个SQL SERVER表中设为自动增加的ID字段给值,
- 如何才能提高?100分求教。(相当于散分)
- CreatePolygonRgn
- 俺今天辞职,散分!!!
- 串口
while not adotable2.Eof do
begin
abc:=adotable1.Fields[0].Value; //adotable1打开了没有?FIelds[0].Value是否可能为NULL? 使用abc:=VarToStr(adotable1.Fields[0].Value);
adoquery1.Active:=false;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from away where name=abc');
adoquery1.Active:=true;
if adoquery1.Eof=true
then
begin
adotable2.Edit; //如果要删除的话,不需要这一句
adotable2.Delete;
end;
//如果不删除,则应该用ADOTable2.Next指向下一个记录,否则会死循环。
end;
不过还是建议采用if adoquery1.eof then ...
不要与true或者false进行比较。
但是FIelds[0].Value可能为NULL,
风舞轻扬大哥还在吗?
adoquery1.SQL.Add('select * from away where name=''abc''');
adoquery1.SQL.Add('select * from away where name=abc');--->错了改成adoquery1.SQL.Add('select * from away where name='''abc'''');
adoquery1.SQL.Add('select * from away where name='''+abc+'''');
adoquery1.SQL.Add('select * from away where name='''+abc+'''');--------------这一贴你看了没阿,老大
(select name from table1)
干吗要一个一个找出来啊
adoquery1.Active:=false;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('delete from adotable2 where name not in (select name from adotable1)');
adoquery1.Active:=true;
end;
运行上面的代码DELPHI说找不到adotable2,我已经添加了一个adotable了啊,而且active也是true,怎么会这样呢?
1。习惯上不要用adoquery1.active:=false OR true 这个一般是作为判断用的
IF NOT adoquery1.active then adoquery1.open
2。你写的SQL也不对要用参数应该这样写:
with adoquery1 do
begin
close;
sql.clear;
sql.add('select * from away where name='''+abc+'''');
open;
end;
3。对于一个数据集不要同时又是Edit状态又要Delete
var
abc:string;
procedure TForm1.Button1Click(Sender: TObject);
begin
if not adotable2.eof then adotable2.First;//要判断一下
while not adotable2.Eof do
begin
if adotable1.Fields[0].Value=NULL then //确保没有空值
abc:=''
else
abc:=adotable1.Fields[0].Value;
adoquery1.close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from away where name='''+abc+'''');
adoquery1.open;
if adoquery1.Eof then adotable2.Delete;
adotable2.next; //你的结构很乱我不知道你在这里用循环的目的要加上这句避免 死循环
end;end;
abc:string;
procedure TForm1.Button1Click(Sender: TObject);
begin
adotable1.open;
adotable2.First;
while not adotable2.Eof do
begin
abc:=adotable1.Fields[0].Value;
adoquery1.Active:=false;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from away where name='''abc'''');
adoquery1.Active:=true;
adoquery1.first;
if adoquery1.Eof=true
then
begin
adotable2.Edit;
adotable2.Delete;
adoquery1.next;
end;
adotable2.close;
end;end;
begin
adoquery1.close;
adoquery1 .SQL.text := 'delete from table1 where name not in (select distinct name from table2)';
adoquery1 .ExecSQL;
end;