你在sql.clear前面,加上 sql.close; 试一试,看看那样行么?:) 或者把你的SQL语句改为:'select number=count(*) number from E_BASIC where ecode='''+edit1.text+'''' 要是你的Ecode字段的类型不是字符型的话,应为:'select number=count(*) number from E_BASIC where ecode='+edit1.text+'' 祝你好运:)
在select里好像不能使用number,将number换另外一个名字就可以,例如: 'select count (*) as a from E_BASIC where ecode='''+edit1.text+'''' 然后fieldbyname('a').Asinteger>0 then其实如果要判断某条记录是否存在可以这样: sql: select * from E_BASIC where ecode='''+edit1.text+'''' 然后判断时: query1.first; if not query1.eof then then showmessage('right'); 执行完sql语句后,指针应该对着满足条件的记录了
select count (ecode) as number from E_BASIC where ecode='''+edit1.text+''''
to LaoZheng: 我用select count (ecode) as number from e_basic where ecode='''+edit1.text+'''; if fieldbyname('ecode').asinteger >0 then show message('found'); 但是仍然出现"未找到预期from关键字”。我昨天试了不用关键字,还是不行的,就用了hzb的后一种方法才运行通过的,就是未用到select(*),今天再试了一遍select(*),倒是可以用了,delphi可真会变的。 我等LaoZheng看一下我上面提的问题后,再来给分哦,不要着急,不要着急,嘻嘻。
为什么不用 with query1 do begin Close; Unprepare; SQL.Clear; SQL.Add('select count (ecode) as number from e_basic where ecode=:ecode'); ParamByName('ecode').AsString:=edit1.text; Prepare; Open; end; if (not query1.fieldbyname('number')=0) then showMessage('right!'); 我一直都是这样用,没问题的。
试一试,看看那样行么?:)
或者把你的SQL语句改为:'select number=count(*) number from E_BASIC where ecode='''+edit1.text+''''
要是你的Ecode字段的类型不是字符型的话,应为:'select number=count(*) number from E_BASIC where ecode='+edit1.text+''
祝你好运:)
'select count (*) as a from E_BASIC where ecode='''+edit1.text+''''
然后fieldbyname('a').Asinteger>0 then其实如果要判断某条记录是否存在可以这样:
sql:
select * from E_BASIC where ecode='''+edit1.text+''''
然后判断时:
query1.first;
if not query1.eof then then
showmessage('right');
执行完sql语句后,指针应该对着满足条件的记录了
我用select count (ecode) as number from e_basic where ecode='''+edit1.text+''';
if fieldbyname('ecode').asinteger >0 then
show message('found');
但是仍然出现"未找到预期from关键字”。我昨天试了不用关键字,还是不行的,就用了hzb的后一种方法才运行通过的,就是未用到select(*),今天再试了一遍select(*),倒是可以用了,delphi可真会变的。
我等LaoZheng看一下我上面提的问题后,再来给分哦,不要着急,不要着急,嘻嘻。
with query1 do
begin
Close;
Unprepare;
SQL.Clear;
SQL.Add('select count (ecode) as number from e_basic where ecode=:ecode');
ParamByName('ecode').AsString:=edit1.text;
Prepare;
Open;
end;
if (not query1.fieldbyname('number')=0) then
showMessage('right!');
我一直都是这样用,没问题的。