我的数据表为 BDE 的,即 扩展名为 db的数据文件,数据文件为access时就可以控制,但是为DB的时候却不行,怎么办,代码如下:
 with table2 do begin
  if not active then open;
  refresh;
  setkey;
  fieldbyname('姓名').asstring:=edit1.text;
  gotokey;
  if gotokey then begin
    showmessage('你所输入的姓名已经存在!!');
    abort;
    end;
   end;

解决方案 »

  1.   

    adoquery1.sql.add('select * from tablename where name='''+edit1.text+'''');
    if not adoquery1.eof then
    showmessage('你所输入的姓名已经存在!!');
      

  2.   

    改用TQuery,用sql语句判断
    function RecordExists:boolean;
    var
      adsTemp:TADODataSet;
    begin
      adsTemp:=TADODataSet.Create;
      adsTemp.Connection:=ADOConnection1;//设置连接
      adsTemp.CommandText:='SELECT 1 FROM Table WHERE 主键字段='+QuotedStr(Edit1.Text)
      try
        adsTemp.Active:=True;
        if adsTemp.RecordCount>0 then
          Result:=True
        else
          Result:=False;
      finally
        adsTemp.Close;
        FreeAdnNil(adsTemp);
      end;
    end;将ado的控件改成bde的
      

  3.   

    用 TOMWLD(笑天)的方法, 你最好是用个主键,免得还要写一堆检测语句来找。