我想根据用户输入的编号来判定,如果数据库中有这条记录则对这条记录的有些字段进行操作,如果没有则打开一个新的窗口,让用户录入详细资料。问:
怎样才能得到根据用户输入的编号来判定数据库中有没有这条记录这返回值?adoquery1.sql.clear;
adoquery1.sql.Text:='select count(*) from numcount where hgnum='trim(edit1.text);
adoquery1.open;
if adoquery1.RecordCount>0 then
 ladel1.caption:=inttostr(adoquery1.Count);
else
 showmessage('没有满足条件的记录');
end;可是这样没有记录时就出错呀?谁有好一点的办法?

解决方案 »

  1.   

    'select count(*) from numcount where hgnum='trim(edit1.text);如果你这样的话,肯定adoquery1.RecordCount = 1你可以这样:'select * from numcount where hgnum='trim(edit1.text);或者select某一字段(速度比较快)
      

  2.   

    如果你非想用'select count(*) from numcount where hgnum='trim(edit1.text);的话,判断条件就要这样写if adoquery1.Fields[0].value = 1 then
     showmessage('有满足条件的记录');
    else
     showmessage('没有满足条件的记录');
    end;
      

  3.   

    用SQL exect 语句应该可以达到你的工作目的。
      

  4.   

    假设你输入的编号是3为,比如‘004’
    对应数据库内部字段是整数类型,例如Code,那么可以这样进行
    with ADOQuery1 do 
    begin
      Close;
      SQL.Text:='Select * From SomeTable Where SomeField='+Trim(IntToStr(StrToInt(Edit1.Text)));  //SomeTable为你的表名,SomeField为你的字段名
      Open;
      if RecordCount>0 then
        ShowMessage('找到符合要求的记录');  //其他相关操作加在这里
      else
        ShowMessage('没有找到符合要求的记录');  //出现新窗口,添加新数据等操作
    end;
      

  5.   

    最后建议你这样写~~~用'select count(1) from numcount where hgnum='trim(edit1.text);
    ...
    if adoquery1.Fields[0].value = 1 then
     showmessage('有满足条件的记录');
    else
     showmessage('没有满足条件的记录');
    end;
    ...
      

  6.   

    if adoquery1.Locate('tablefield',trim(edit1.text),[]) then
      

  7.   

    if adoquery1.Locate('tablekey','bianliang',[]) then
      

  8.   

    各位当数据库中没有用户输入编号的记录时提示出错,怎么解决?出错提示为:Project project2.exe raised exception class EOLeException with message 'BOF或EOF中有一个是"真"或者当前的记录已被删除,所需的操作要求一个当前的记录'。process stopped .Use step or Run to Continue?还有一问,我在打开一个昨天写的程序时,delphi提示:Exception EOLeException in module .VCLADO50.BPL at 0000A39C 超时过期?
    这个错什么意思?
      

  9.   

    ADOQuery1.Close;
          ADOQuery1.SQL.Clear;
          ADOQuery1.SQL.add('select * from numcount');
          ADOQuery1.ExecSQL;
          ADOQuery1.Open ;
          ADOQuery1.First;
          if DM_client.ADOQuery1.Locate('hgnum','trim(edit1.text),[locaseinsensitive]) then
            ladel1.caption:=inttostr(adoquery1.Count)
         else
            begin
              showmessage('没有满足条件的记录');
            end;
      

  10.   


    1.记录集为NULL,要不你的表中没有记录,你要进行处理的,你加上ADOQuery1.First;试试。2.可能你数据库大,连接超时,你可以把ADOConnection1的连接时间设置大一点,
     如:ADOConnection1.CommandTimeout:=35;