帮忙看看,程序在D4下已通过,D5下ApplyUpdate如何改?
//query2.datasource->query1,DataSetProvider1->Query1
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
DBTables, Grids, DBGrids, Provider, DBClient, Db, StdCtrls, ExtCtrls,
DBCtrls, BdeProv;
type
TForm1 = class(TForm)
Database1: TDatabase;
Query1: TQuery;
DataSource1: TDataSource;
Query2: TQuery;
DataSource2: TDataSource;
ClientDataSet1: TClientDataSet;
DBGrid1: TDBGrid;
DBGrid2: TDBGrid;
DataSource3: TDataSource;
NestedTable1: TNestedTable;
DataSource4: TDataSource;
ClientDataSet2: TClientDataSet;
DBNavigator1: TDBNavigator;
Button1: TButton;
DataSetProvider1: TDataSetProvider;
procedure Query1AfterOpen(DataSet: TDataSet);
procedure ClientDataSet1AfterOpen(DataSet: TDataSet);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Query1AfterOpen(DataSet: TDataSet);
var i:integer;
begin
for I := 0 to DataSet.FieldCount - 1do
if DataSet.Fields.DataType in [ftDataSet, ftReference] then
begin
NestedTable1.DataSetField := TDataSetField(DataSet.Fields);
end;
end;
procedure TForm1.ClientDataSet1AfterOpen(DataSet: TDataSet);
var i:integer;
begin
for I := 0 to DataSet.FieldCount - 1do
if DataSet.Fields.DataType in [ftDataSet, ftReference] then
begin
ClientDataSet2.DataSetField := TDataSetField(DataSet.Fields);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var Delta, Results: Variant;
errorcount:integer;
begin
Delta:=ClientDataset1.Delta;
Results:=ClientDataset1.Provider.ApplyUpdates(delta, -1, errorcount);
ClientDataset1.Reconcile(Results);
end;
end.
//From1.dfm
object Form1: TForm1
Left = 210
Top = 185
Width = 544
Height = 375
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 = 16
Top = 64
Width = 320
Height = 120
DataSource = DataSource3
TabOrder = 0
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
end
object DBGrid2: TDBGrid
Left = 16
Top = 192
Width = 320
Height = 120
DataSource = DataSource4
TabOrder = 1
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
end
object DBNavigator1: TDBNavigator
Left = 16
Top = 40
Width = 240
Height = 25
DataSource = DataSource3
TabOrder = 2
end
object Button1: TButton
Left = 368
Top = 32
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 3
OnClick = Button1Click
end
object Database1: TDatabase
AliasName = 'DBDEMOS'
Connected = True
DatabaseName = 'db'
LoginPrompt = False
SessionName = 'Default'
Left = 16
Top = 16
end
object Query1: TQuery
Active = True
AfterOpen = Query1AfterOpen
DatabaseName = 'db'
RequestLive = True
SQL.Strings = (
'select * from Customer')
Left = 56
Top = 16
end
object DataSource1: TDataSource
DataSet = Query1
Left = 112
Top = 16
end
object Query2: TQuery
Active = True
DatabaseName = 'db'
DataSource = DataSource1
RequestLive = True
SQL.Strings = (
'select * from Orders where CustNo=:CustNo')
Left = 192
Top = 16
ParamData = <
item
DataType = ftFloat
Name = 'CustNo'
ParamType = ptUnknown
end>
end
object DataSource2: TDataSource
DataSet = Query2
Left = 232
Top = 16
end
object ClientDataSet1: TClientDataSet
Active = True
Aggregates = <>
Params = <>
ProviderName = 'DataSetProvider1'
AfterOpen = ClientDataSet1AfterOpen
Left = 24
Top = 56
end
object DataSource3: TDataSource
DataSet = ClientDataSet1
Left = 56
Top = 64
end
object NestedTable1: TNestedTable
Left = 352
Top = 16
end
object DataSource4: TDataSource
DataSet = ClientDataSet2
Left = 120
Top = 216
end
object ClientDataSet2: TClientDataSet
Aggregates = <>
Params = <>
Left = 56
Top = 216
end
object DataSetProvider1: TDataSetProvider
DataSet = Query1
Left = 152
Top = 16
end
end