unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    ADOTable1: TADOTable;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    Edit1: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Button2: TButton;
    Edit2: TEdit;
    Edit3: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  if edit1.text<>'' then
    if ADOTable1.Locate('CustNo',edit1.text,[loPartialKey]) then
    begin
       edit2.Text:= ADOTable1.FieldValues['Phone'];
       edit3.Text:= ADOTable1.FieldValues['Contact']
    end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
ADOTable1.Edit;  //将数据集设为编辑状态
ADOTable1.FieldValues['Phone']:=Edit2.Text; //将Edit2中的内容赋给字段
ADOTable1.FieldValues['Contact']:=Edit3.Text; //将Edit3中的内容赋给字段
ADOTable1.Post;  //提交到数据库保存
end;

end.
