我也没好办法,只在保存前用 Query 查一下是有此记录,如有,则给出提示信息With ADOQuery do begin if Active then Close; SQL.Clear; SQL.Add('select MyNo from MyTable where MyNo=' + IntToStr(MyNo)); Open; If not Eof then begin Close; ShowMessage('主键重复'); Abort; end; Close; end;
用locate吧,看一下,我想会有帮助的 function Locate(const KeyFields: string; const KeyValues: Variant; Options: TLocateOptions): Boolean; virtual;DescriptionThis function returns False, indicating that a matching record was not found and the cursor is not repositioned.Descendant classes override this method so that it locates the record where the fields identified by the comma-delimited string KeyFields have the values specified by the Variant or Variant array KeyValues. Options indicates whether the search is case insensitive and whether partial matches are supported. Locate should return True if a record is found that matches the specified criteria and the cursor repositioned to that record.
Query 查一下是有此记录,如有,则给出提示信息With ADOQuery do
begin
if Active then Close;
SQL.Clear;
SQL.Add('select MyNo from MyTable where MyNo=' + IntToStr(MyNo));
Open;
If not Eof then
begin
Close;
ShowMessage('主键重复');
Abort;
end;
Close;
end;
function Locate(const KeyFields: string; const KeyValues: Variant; Options: TLocateOptions): Boolean; virtual;DescriptionThis function returns False, indicating that a matching record was not found and the cursor is not repositioned.Descendant classes override this method so that it locates the record where the fields identified by the comma-delimited string KeyFields have the values specified by the Variant or Variant array KeyValues. Options indicates whether the search is case insensitive and whether partial matches are supported. Locate should return True if a record is found that matches the specified criteria and the cursor repositioned to that record.