2,498
社区成员
发帖
与我相关
我的任务
分享
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls;
type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
Label1: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Label2: TLabel;
Label3: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if trim(edit1.Text)='' then
begin
showmessage ( '请输入工号,该项为必填项! ');
end;
if trim(edit3.Text)<>'' then
begin
with adoquery1 do
begin
close;
sql.Clear ;
sql.Add('insert into mestab (workid,name,age)');
sql.add('values (:A,:B,:C)');
parameters.ParamByName('A').Value :=strtoint(trim(edit1.text));
parameters.ParamByName('B').Value :=trim(edit2.text);
parameters.ParamByName('C').Value :=trim(edit3.text);
execsql;
end;
edit1.Text:='';
edit2.Text:='';
edit3.Text:='';
end;
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls;
type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
Label1: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Label2: TLabel;
Label3: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if trim(edit1.Text)='' then
begin
showmessage ( '请输入工号,该项为必填项! ');
end;
if trim(edit1.Text)<>'' then
begin
try//捕捉异常
with adoquery1 do
begin
close;
sql.Clear ;
sql.Add('insert into mestab (workid,name,age)');
sql.add('values (:A,:B,:C)');
parameters.ParamByName('A').Value :=strtoint(trim(edit1.text));
parameters.ParamByName('B').Value :=trim(edit2.text);
parameters.ParamByName('C').Value :=trim(edit3.text);
execsql;
end;
edit1.Text:='';
edit2.Text:='';
edit3.Text:='';
except//处理异常
application.MessageBox('系统错误,可能存在主键重复情况,请核对固定资产编号是否重复!','提示',0+64) ;
close;
end;
end;
end;
end.
我改了下,不过是不是太简单了,就这样处理合适吗?有全面点的吗?请教下