if adodataset.Locate('CpCode','01#',[]) then  
       begin
         MsgDlg(‘已经存在该纪录’);
         Abort;
       end;
数据库中明明有这条纪录,但是就是定位不到,为什么?

解决方案 »

  1.   

    adodataset.Locate('CpCode','01#',[loPartialKey]) 
      

  2.   

    adodataset.Locate('CpCode','01#',[loPartialKey]) 
    使用这句还是不能定位
      

  3.   

    adodataset的查询结果里有这个记录么?
      

  4.   


    if adodataset.Locate('CpCode','01#',[]) then            MsgDlg(‘已经存在该纪录’); 
      

  5.   

    自己遍历一下吧,效率可能就比较低了//你这个问题可能是因为数据有空格的原因,自己遍历比较一下看看行不行
    function LocateEx(DataSet: TDataSet; Field, Value: String): Boolean;
    var
      BK: TBookStr;
      AField: TField;
    begin
      Result := False;
      if DataSet.IsEmpty then Exit;  AField := DataSet.FindField(Field)
      if AField = nil then Exit;  DataSet.DisableControls;
      try
        BK := DataSet.Book;
        DataSet.First;
        Value := Trim(Value);
        while not DataSet.Eof do
        begin
          if SameText(Trim(AField.AsString), Value) then
          begin
            Result := True;//找到相应记录就退出吧
            Exit;
          end;
          DataSet.Next;
        end;
        DataSet.Book := BK;//没有找到就把数据集滚到原来的位置
      finally
        DataSet.EnableControls;
      end;
    end;