?? unit3.pas
字號:
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls, Buttons;
type
TForm3 = class(TForm)
ADOQuery1: TADOQuery;
BitBtn1: TBitBtn;
txt_sName: TEdit;
Label1: TLabel;
Label2: TLabel;
txt_sPhone: TEdit;
txt_sID: TEdit;
Label3: TLabel;
BitBtn2: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
Uses unit1;
{$R *.dfm}
procedure TForm3.BitBtn1Click(Sender: TObject);
Var n:Integer;
begin
With AdoQuery1 do
Try
if Not Active then Open;
if IsEmpty then Exit;
//
txt_sID.Text:=FieldValues['sID'];
txt_sName.Text:=FieldByName('sName').AsString;
txt_sPhone.Text:= FieldByName('sPhone').Value;
//
Close;
Except
On X:Exception do ShowMessage('調用數據顯示出錯!'+#13+X.Message);
End;
end;
procedure TForm3.BitBtn2Click(Sender: TObject);
begin
With AdoQuery1 do
Try
if txt_sID.Text='' then Raise Exception.Create('編號主鍵不能是空的!');
//首先檢查是否存在該記錄
Close;
SQL.Text:='Select * From Employee Where sID='+QuotedStr(txt_sID.Text);
Open;
//如果沒有該數據
if IsEmpty then Begin
SQL.Text:='Insert Into Employee ';
SQL.Add(' (sID, sName, sPhone) ');
SQL.Add('Values(:sID, :sName, :sPhone)' );
End
Else Begin //若沒有數據
SQL.Text:='Update Employee Set ';
SQL.Add(' sName=:sName, sPhone=:sPhone ');
SQL.Add(' Where sID=:sID');
End;
//公共參數
Parameters.ParamValues['sID']:=txt_sID.Text;
Parameters.ParamValues['sName']:=txt_sName.Text;
Parameters.ParamByName('sPhone').Value:=txt_sPhone.Text;
//執行
ExecSQL;
//完成
Messagebox(Handle,'完成!','OK',0);
Except
On E:Exception do ShowMessage('更新完畢!'+#13+E.Message);
End;
end;
procedure TForm3.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action:=caFree;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -