动态创建SQLDATASET,CLIENTDATASET 获取数据.CLIENTDATASET 关联的DATASETPIOVIDER 怎么关联CLIENTDATASET 关联的DATASETPIOVIDER 怎么关联
function GetDir(aSql:string;var cds:TClientDataSet):Boolean; var aTempSqlDataSet:TSQLDataSet; aTempProvider:TDataSetProvider; aTempCds:TClientDataSet; aStream:TStream; begin try aTempSqlDataSet:=TSQLDataSet.Create(nil); aTempProvider:=TProvider.Create(nil); aTempCds:=TClientDataSet.Create(nil); aTempSqlDataSet.SQLConnection:=DM.FBCON; aTempProvider.DataSet:=aTempSqlDataSet; aTempCds.Data:=aTempProvider.Data;//missing query.... aTempSqlDataSet.Active:=False; aTempCds.Active:=False; aTempSqlDataSet.CommandText:=aSql; aTempSqlDataSet.Open; aTempCds.Open; aTempCds.SaveToStream(aStream); cds.LoadFromStream(aStream); finally FreeAndNil(aTempSqlDataSet); FreeAndNil(aTempProvider); FreeAndNil(aTempCds); end; end;
function GetDir(aSql:string;var cds:TClientDataSet):Boolean; var aTempSqlDataSet:TSQLDataSet; aTempProvider:TDataSetProvider; aTempCds:TClientDataSet; begin try aTempSqlDataSet:=TSQLDataSet.Create(nil); aTempProvider:=TProvider.Create(nil); aTempCds:=TClientDataSet.Create(nil); aTempSqlDataSet.SQLConnection:=DM.FBCON; aTempProvider.DataSet:=aTempSqlDataSet; aTempProvider.Name:='aTempProvider'; aTempCds.SetProvider(aTempProvider); aTempSqlDataSet.Active:=False; aTempCds.Active:=False; aTempSqlDataSet.CommandText:=aSql; aTempSqlDataSet.Open; aTempCds.Open; cds.CloneCursor(aTempCds,True,False); finally FreeAndNil(aTempSqlDataSet); FreeAndNil(aTempProvider); FreeAndNil(aTempCds); end;