cj/大虾,一个clientdataset applyupdate时拆为三个数据集(100分)

  • 主题发起人 主题发起人 Chxn
  • 开始时间 开始时间
C

Chxn

Unregistered / Unconfirmed
GUEST, unregistred user!
这样的,数据库中有三个表,client端的数据集为这三个表的集合,insert/update时,将这个数据集apply到appserver,怎样将他拆开。
谢谢各位。
如果分数给少了,可以加
 
当把server端3个表的数据集中到client一个表时,就应该有一个字段标明
每条纪录属于那一个表,并且client新添加的纪录也必须在该字段标明属于
何表,这样更新时就可以:
INSERT INTO Table1 .... WHERE OnwerTable=1
INSERT INTO Table2 .... WHERE OnwerTable=2
INSERT INTO Table3 .... WHERE OnwerTable=3
你如果不用一个字段来保留这些信息,全都混杂在一起,那谁也没办法分得出来.
 
呵呵, query中只有一些类型支持update, 如果是max, min....怎么也不能update.
所以, 要根据你的实际数据, 更新不同的表就可以了.
如insert into t4 (f1,f2,f3,f4) values (1,2,3,4)
其中f4是primary id.
就可以拆成:
insert into t1 (f1,f4) values (1,4)
insert into t2 (f2,f4) values (2,4)
insert into t3 (f3,f4) values (3,4)
 
问题是我用的是midas+clientdataset
程序写在那个事件?
给个demo吧
chxn@263.net
 
hehe clientdataset has commandtext property now in delphi 5
but i stilldo
not understand:(
 
使用TCustomProvider.OnDataRequest
 
通过ClientDataSet.Provider.DataRequest('')传递空字符串来激发应用服务器
段的OnDataRequest事件,在OnDataRequest事件中调用TQuery的Open或ExecSql
方法
ClientDataSet.Provider.DataRequest可将Sql语句动态的传递到应用服务器端

应用服务器端:
function TQueryDemo.AdHocProviderDataRequest(Sender: TObject;
Input: OleVariant): OleVariant;
begin
Query1.ExecSQL;
end;
客户端
procedure TForm1.RunButtonClick(Sender: TObject);
begin
{ Send the query string to the server and try to open the client dataset }
ClientData.Close;
ClientData.Provider.DataRequest(SQL.Lines.Text);
end;

可仔细分析demos/midas/adhoc目录下的例子,相信有不小的收获
 
liu jzx:谢谢
一个奇怪现象,程序在我的机子(nt40+sp5)不运行,别的w98/nt40+sp5
可以。提示odbc参数不足,我的机子应如何配置?
 
呵呵, 又是odbc问题, 最简单的解决方法, 找mdac_typ.exe然后运行, 里面包括
m$的所有数据库odbc驱动.
 
cytown:我已经装了全部驱动
 
我也觉得是CYTOWN说的问题,你两台机器的ODBC设置一样吗?其它相关设置呢?//别问我相关指什么
 
你先要odbc测试是通的才行:-|
 
要odbc测试是通的,行!
 
帮忙看看,程序在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
 
多人接受答案了。
 
后退
顶部