当新增记录时 有判断编号是否与 存在,如果存在则不保存。
修改:修改操作不对编号进行修改。[@more@]
private
{ Private declarations }
cActive:string; //设置新增'I'、修改标志'U':
procedure TEduForm.SaveBtnClick(Sender: TObject);
var
csql:string;
begin //保存学历资料。
If cActive='I' Then
begin
with udm.Qry_edu do
begin
close;
sql.Clear;
sql.Add('select * from bas_education where eduNo='+quotedStr(trim(EduNoEdt.Text))) ;
open;
if udm.Qry_edu.RecordCount>0 then
begin
application.MessageBox('已经存在','提示',0+64);
exit;
end;
end;
csql:= 'insert into bas_education (eduNo,eduName,eduMemo) values ('+quotedstr(trim(eduNoEdt.Text))+','+quotedStr(EduNameEdt.Text);
csql:=csql+','+quotedStr(eduMemoEdt.Text)+')';
with udm.Qry_edu do
begin
close;
sql.Clear;
sql.Add(csql);
try
ExecSQL ;
showMessage('保存成功!');
except
exit;
showMessage('保存成功!');
end;
end;
saveBtn.Enabled:=false;
deleteBtn.Enabled:=false;
cancelBtn.Enabled:=false;
end; // if active=I end;
if cactive='U' then
begin //注:编号不作修改对象
csql:='update bas_education set eduName='+quotedStr(trim(EduNameEdt.Text)) ;
csql:=csql+',eduMemo=' +quotedstr(trim(EduMemoEdt.Text));
csql:=csql+' where eduNo=' +quotedStr(trim(eduNoedt.Text));
with udm.Qry_edu do
begin
close;
sql.Clear;
sql.Add(csql);
try
ExecSQL ;
showMessage('保存成功!');
except
exit;
showMessage('保存成功!');
end;
end;
end;
end;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/729024/viewspace-1021351/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/729024/viewspace-1021351/