在输入记录时,怎样知道那个字段的值是已存在的?然后执行相应的动作,我用的是ADO。

解决方案 »

  1.   

    用SQL语句可以搞定,在ADOQuery中的SQL中写入如下语句
    if not exists (select 1 from table where fieldname=input)
     insert into table (field1,field2...) values(in_v1,in_v2....)
    其中input为你所知字段的值。
      

  2.   

    我是这样用的
    先建立一个动态的tclientdataset,然后拷贝你的内容
    var td:tclientdataset;
    begin
       td:=tclientdataset.create(nil);
       td.currosur(dataset,false,false);
       if td.locate(field,youinput,[])=true then
          //your source
       else
         // your source
       end;
    //可能有输入错误
      

  3.   

    adoquery.beforepost
    begin
    以输入的数据查询数据库
    如果找到
    exit;end;
      

  4.   

    判断有没有“张”这个人
    adoquery1.sql.clear;
    adoquery1.sql.add('select * from tablename where fieldname=''张''')
    adoquery1.close;
    adoquery1.open;
    if adoquery1.eof=false then 
    showmessage('找到张的记录,一共'+inttostr(adoquery1.recordcount)+'条')
    else
    showmessage('没有张的记录');
      

  5.   

    看个函数,希望对你有帮助!
    function GetRecCount(strParam, ValParam, strTable: string; AdoQry: TADOQuery):Integer;var strsql:string;
    begin
      try
        strsql := 'select Count('+ strParam +') As RecCount';
        strsql := strsql + ' from '+ strTable +'';
        strsql := strsql + ' where '+ strParam +'='''+ ValParam +'''';
        RunSQL(AdoQry,strsql);
        Result := AdoQry.FieldByName('RecCount').Value;
      except
        Result := 0;
        Abort;
      end;
    end;
      

  6.   

    if not exists (select 1 from table where fieldname=input)
     insert into table (field1,field2...) values(in_v1,in_v2....)
      

  7.   

    同意各位兄弟的看法,写之前查一查就是这是我的问题 看看吧 I Beg You,thanks!
    http://expert.csdn.net/Expert/topic/2194/2194653.xml?temp=.1814386