unit main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids, DBGrids, DBTables, DB, ADODB;

type
  TForm1 = class(TForm)
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    btnUpdate: TButton;
    edtNo: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    edtLastname: TEdit;
    ADOQuery1: TADOQuery;
    ADOTable1: TADOTable;
    ADOConnection1: TADOConnection;
    procedure btnUpdateClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btnUpdateClick(Sender: TObject);
var s:String;
begin
  //更新指定员工编号的LastName
  with ADOQuery1 do
  begin
    if Active then
       Close;   //关闭数据集
    SQL.Clear ;
    s := 'update employee set LastName = ''' + edtLastname.Text + '''' +
              ' where EmpNo = ' + edtNo.Text ;
    SQL.Add(s);
    showmessage(s);
    ExecSQL;    //执行update语句
  end;

  //更新显示
  With ADOTable1 do
  begin
    Active := False;
    Open;
    Locate('EmpNo', edtNo.Text, []);
  end;
end;

end.
