急!!!在dbgrid1中,我如果编辑table1时就判断是否在table2中有这个值,怎么做啊?
如果在table2中的有的话,我就不能再table1中输入相同的值了

解决方案 »

  1.   

    var 
      str:string;
    begin  str:=table1.fieldbyname('字段名').asstring;//要编辑的table1中的值  table2.close;
      table2.open;
      table2.first;
      if table2.locat('table2的字段名',str,[]) then
      begin//如果此值在table2表中被定位到
        messagedlg(#13'此值在table2表中已经存在了。',mtinformation,[mbok],0);
        exit;
      end else//如果此值在table2表中没被定位到
      begin
        //可做的操作
      end;
    end;
      

  2.   

    if Table2.Locate('字段名',值,[loCaseInsensitive, loPartialKey]) then
    begin
      showmessage('该值已经存在,不能编辑');
      exit;
    end;
      

  3.   

    如果是索引字段
    直接用Filter检测