with ADOQuery do try Close; SQL.Clear; SQL.Add('select count(*) cnt from table1 where id='+IntToStr(MyID)); Open; if FieldByName('cnt').asInteger>0 then showmessage('存在该ID') else showMessage('不存在该ID'); finally Close; end
to newyj 有个问题,我不想把表做死,打算写这样的函数:function TfrmProduceEdit.TheFieldIsExit(strCheckedID:string;strTable:string):boolean;strTable即为要访问的表,有很多这样的处理,不可能一个就对应一个query,
to Caty :你的方法是一个思路,以前试过,好像是可以的。
with dmADO.queryCheckID do begin close; sql.clear; sql.Add ('select ProduceID from ' + strTable + ' where ProduceID=' + strCheckedID); open; if recordcount>0 then result :=true else result :=false; end;上面有什么样的问题?
先用ADOQuery列出所用纪录 select * from 表 if ADOQuery.Locate('ID',ID,[loCaseInsensitive]) then 有 else 无
try
Close;
SQL.Clear;
SQL.Add('select count(*) cnt from table1 where id='+IntToStr(MyID));
Open;
if FieldByName('cnt').asInteger>0 then showmessage('存在该ID')
else showMessage('不存在该ID');
finally
Close;
end
有个问题,我不想把表做死,打算写这样的函数:function TfrmProduceEdit.TheFieldIsExit(strCheckedID:string;strTable:string):boolean;strTable即为要访问的表,有很多这样的处理,不可能一个就对应一个query,
close;
sql.clear;
sql.Add ('select ProduceID from ' + strTable + ' where ProduceID=' + strCheckedID);
open;
if recordcount>0 then
result :=true
else
result :=false;
end;上面有什么样的问题?
select * from 表
if ADOQuery.Locate('ID',ID,[loCaseInsensitive]) then
有
else
无
close;
sql.Add();
Open;
你可以直接填写Query的SQL属性
每次只需
Close;
Open;
你到底明白没有?你的意思我知道,如果不明白的话可以email给我(我有解决的办法)
[email protected]