unit main;

interface

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

type
  TForm1 = class(TForm)
    Table1: TTable;
    DataSource1: TDataSource;
    Query1: TQuery;
    DBGrid1: TDBGrid;
    btnUpdate: TButton;
    edtNo: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    edtLastname: TEdit;
    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 Query1 do
  begin
    if Active then
       Close;   //关闭数据集
    SQL.Clear ;
    s := 'update employee set LastName = ''' + edtLastname.Text + '''' +
              ' where EmpNo = ''' + edtNo.Text + '''';
    SQL.Add(s);
    Prepare;
    ExecSQL;    //执行update语句
  end;

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

end.
