建立了2个测试表,和你的类似,但没有memo字段。测试通过。记得给分。dfm文件:object Form1: TForm1 Left = 119 Top = 176 Width = 720 Height = 500 Caption = 'Form1' Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'MS Sans Serif' Font.Style = [] OldCreateOrder = False PixelsPerInch = 96 TextHeight = 13 object DBGrid1: TDBGrid Left = 24 Top = 40 Width = 521 Height = 345 DataSource = DataSource1 TabOrder = 0 TitleFont.Charset = DEFAULT_CHARSET TitleFont.Color = clWindowText TitleFont.Height = -11 TitleFont.Name = 'MS Sans Serif' TitleFont.Style = [] end object BtnOpen: TButton Left = 576 Top = 56 Width = 75 Height = 25 Caption = '´ò¿ªÊý¾Ý¼¯' TabOrder = 1 OnClick = BtnOpenClick end object DataSource1: TDataSource DataSet = ClientDataSet1 Left = 176 Top = 224 end object ClientDataSet1: TClientDataSet Aggregates = <> Params = <> ProviderName = 'DataSetProvider1' BeforePost = ClientDataSet1BeforePost AfterPost = ClientDataSet1AfterPost BeforeDelete = ClientDataSet1BeforeDelete AfterDelete = ClientDataSet1AfterDelete Left = 120 Top = 240 end object DataSetProvider1: TDataSetProvider DataSet = ADOQuery1 Options = [poAllowCommandText] Left = 120 Top = 280 end object ADOQuery1: TADOQuery Connection = ADOConnection1 Parameters = <> Left = 128 Top = 336 end object ADOConnection1: TADOConnection ConnectionString = 'Provider=MSDASQL.1;Password="";Persist Security Info=True;Data S' + 'ource=Acctest' LoginPrompt = False Provider = 'MSDASQL.1' Left = 176 Top = 336 end object ADOCommand1: TADOCommand Connection = ADOConnection1 Parameters = <> Left = 176 Top = 392 endend--------------------------------------pas 文件:unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, DB, ADODB, Provider, DBClient, Grids, DBGrids;type TForm1 = class(TForm) DBGrid1: TDBGrid; DataSource1: TDataSource; ClientDataSet1: TClientDataSet; DataSetProvider1: TDataSetProvider; ADOQuery1: TADOQuery; ADOConnection1: TADOConnection; BtnOpen: TButton; ADOCommand1: TADOCommand; procedure ClientDataSet1AfterPost(DataSet: TDataSet); procedure ClientDataSet1BeforeDelete(DataSet: TDataSet); procedure BtnOpenClick(Sender: TObject); procedure ClientDataSet1AfterDelete(DataSet: TDataSet); procedure ClientDataSet1BeforePost(DataSet: TDataSet); private { Private declarations } FStatusFilter:TUpdateStatus; procedure DoInsert; procedure DoUpdate; public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.ClientDataSet1BeforePost(DataSet: TDataSet);begin IF ClientDataSet1.State=dsInsert then FStatusFilter:=usInserted else FStatusFilter:=usModified;end;procedure TForm1.ClientDataSet1AfterPost(DataSet: TDataSet);begin if FStatusFilter=usInserted then //²é¿´µ±Ç°¼Ç¼ÊÇÐÂÔö/Ð޸ĺóµÄÊý¾Ý DoInsert else if FStatusFilter=usModified then DoUpdate; ClientDataSet1.MergeChangeLog;end;procedure TForm1.ClientDataSet1BeforeDelete(DataSet: TDataSet);begin ADOCommand1.CommandText:=format('Delete from StockBill where Autoid=%d ',[ClientDataSet1.FieldByName('Autoid').AsInteger] ); ADOCommand1.Execute;end;procedure TForm1.ClientDataSet1AfterDelete(DataSet: TDataSet);begin ClientDataSet1.MergeChangeLog; //Çå³ýÈÕÖ¾end;procedure TForm1.BtnOpenClick(Sender: TObject);begin ClientDataSet1.Close; ClientDataSet1.CommandText:=' select a.*, b.GoodsName, b.unit '+ 'from StockBill a, Goods b '+ 'where a.GoodsId = b.autoid '; ClientDataSet1.Open;end;procedure TForm1.DoInsert;var S:String;begin S:=Format('Insert into StockBill values (%d, ''%s'', %d, %d, #%s#) ', [ClientDataSet1.FieldByName('Autoid').AsInteger, ClientDataSet1.FieldByName('BillNo').AsString, ClientDataSet1.FieldByName('GoodsId').AsInteger, ClientDataSet1.FieldByName('BillNum').AsInteger, ClientDataSet1.FieldByName('OperateDate').AsString ]); ADOCommand1.CommandText:=S; ADOCommand1.Execute;end;procedure TForm1.DoUpdate;var S:String;begin S:=Format('Update StockBill '+ 'Set BillNo=''%s'', '+ ' GoodsId=%d, '+ ' BillNum=%d, '+ ' OperateDate= #%s# '+ 'Where Autoid=%d ', [ClientDataSet1.FieldByName('BillNo').AsString, ClientDataSet1.FieldByName('GoodsId').AsInteger, ClientDataSet1.FieldByName('BillNum').AsInteger, ClientDataSet1.FieldByName('OperateDate').AsString, ClientDataSet1.FieldByName('Autoid').AsInteger ]); ADOCommand1.CommandText:=S; ADOCommand1.Execute;end;end.