L
luckj
Unregistered / Unconfirmed
GUEST, unregistred user!
//出错提示 missing data provider or data packet
unit MyADO;
interface
uses
SysUtils,DB, ADODB, DBClient, Provider;
type
TMyDateUpdata = class
FADOQ: TADOQuery;
FDSProvider: TDataSetProvider;
FClientDataSet: TClientDataSet;
FADOConn: TADOConnection;
public
constructor Create(Conn:string);
destructor Destroy;
function UpdateXMLTODB(XMLPath:string):boolean;
end;
implementation
uses unit1;
{ TMyDateUpdata }
constructor TMyDateUpdata.Create(Conn:string);
begin
FADOConn:= TADOConnection.Create(nil);
FADOQ:= TADOQuery.Create(Nil);
FClientDataSet:= TClientDataSet.Create(nil);
FDSProvider:= TDataSetProvider.Create(nil);
//设置FADOConn
FADOConn.CommandTimeout:=30;
FADOConn.ConnectionString:= Conn;
FADOConn.ConnectionTimeout:=15;
FADOConn.CursorLocation := clUseClient;
FADOConn.ConnectOptions:= coConnectUnspecified;
FADOConn.KeepConnection :=true;
FADOConn.LoginPrompt :=false;
FADOConn.Provider:= 'SQLOLEDB.1';
//设置FADOQ
FADOQ.Connection :=FADOConn;
FADOQ.AutoCalcFields :=true;
FADOQ.CacheSize :=2;
FADOQ.CommandTimeout :=30;
FADOQ.CursorLocation :=clUseClient;
FADOQ.CursorType := ctStatic;
FADOQ.LockType:= ltOptimistic;
FADOQ.MarshalOptions := moMarshalAll;
FADOQ.ParamCheck:=true;
//设置FDSProvider
FDSProvider.Name := 'FDSProvider' ;
FDSProvider.DataSet:= FADOQ;
FDSProvider.Exported:=true;
FDSProvider.ResolveToDataSet:=false;
FDSProvider.UpdateMode:=upWhereKeyOnly;
FDSProvider.Options := [poallowcommandtext];
//设置FClientDataSet
FClientDataSet.AggregatesActive:=false;
FClientDataSet.AutoCalcFields:=true;
FClientDataSet.DisableStringTrim :=false;
FClientDataSet.FetchOnDemand:=true;
FClientDataSet.ObjectView :=true;
FClientDataSet.ReadOnly :=false;
FClientDataSet.StoreDefs :=true;
FClientDataSet.ProviderName := FDSProvider.Name ;
//test
FADOConn.Connected:=true;
FClientDataSet.CommandText :='select * from Employees';
FClientDataSet.Active :=true;//出错 missing data provider or data packet
end;
destructor TMyDateUpdata.Destroy;
begin
FADOQ.Close;
Freeandnil(FADOQ) ;
Freeandnil(FDSProvider) ;
Freeandnil(FClientDataSet) ;
Freeandnil(FADOConn) ;
end;
function TMyDateUpdata.UpdateXMLTODB(XMLPath: string):boolean;
begin
Result:=true;
if self <>nil then
begin
try
FClientDataSet.LoadFromFile(XMLPath);
FClientDataSet.ApplyUpdates(0);
except
Result:=false;
end;
end
else
Result:=false;
end;
end.
unit MyADO;
interface
uses
SysUtils,DB, ADODB, DBClient, Provider;
type
TMyDateUpdata = class
FADOQ: TADOQuery;
FDSProvider: TDataSetProvider;
FClientDataSet: TClientDataSet;
FADOConn: TADOConnection;
public
constructor Create(Conn:string);
destructor Destroy;
function UpdateXMLTODB(XMLPath:string):boolean;
end;
implementation
uses unit1;
{ TMyDateUpdata }
constructor TMyDateUpdata.Create(Conn:string);
begin
FADOConn:= TADOConnection.Create(nil);
FADOQ:= TADOQuery.Create(Nil);
FClientDataSet:= TClientDataSet.Create(nil);
FDSProvider:= TDataSetProvider.Create(nil);
//设置FADOConn
FADOConn.CommandTimeout:=30;
FADOConn.ConnectionString:= Conn;
FADOConn.ConnectionTimeout:=15;
FADOConn.CursorLocation := clUseClient;
FADOConn.ConnectOptions:= coConnectUnspecified;
FADOConn.KeepConnection :=true;
FADOConn.LoginPrompt :=false;
FADOConn.Provider:= 'SQLOLEDB.1';
//设置FADOQ
FADOQ.Connection :=FADOConn;
FADOQ.AutoCalcFields :=true;
FADOQ.CacheSize :=2;
FADOQ.CommandTimeout :=30;
FADOQ.CursorLocation :=clUseClient;
FADOQ.CursorType := ctStatic;
FADOQ.LockType:= ltOptimistic;
FADOQ.MarshalOptions := moMarshalAll;
FADOQ.ParamCheck:=true;
//设置FDSProvider
FDSProvider.Name := 'FDSProvider' ;
FDSProvider.DataSet:= FADOQ;
FDSProvider.Exported:=true;
FDSProvider.ResolveToDataSet:=false;
FDSProvider.UpdateMode:=upWhereKeyOnly;
FDSProvider.Options := [poallowcommandtext];
//设置FClientDataSet
FClientDataSet.AggregatesActive:=false;
FClientDataSet.AutoCalcFields:=true;
FClientDataSet.DisableStringTrim :=false;
FClientDataSet.FetchOnDemand:=true;
FClientDataSet.ObjectView :=true;
FClientDataSet.ReadOnly :=false;
FClientDataSet.StoreDefs :=true;
FClientDataSet.ProviderName := FDSProvider.Name ;
//test
FADOConn.Connected:=true;
FClientDataSet.CommandText :='select * from Employees';
FClientDataSet.Active :=true;//出错 missing data provider or data packet
end;
destructor TMyDateUpdata.Destroy;
begin
FADOQ.Close;
Freeandnil(FADOQ) ;
Freeandnil(FDSProvider) ;
Freeandnil(FClientDataSet) ;
Freeandnil(FADOConn) ;
end;
function TMyDateUpdata.UpdateXMLTODB(XMLPath: string):boolean;
begin
Result:=true;
if self <>nil then
begin
try
FClientDataSet.LoadFromFile(XMLPath);
FClientDataSet.ApplyUpdates(0);
except
Result:=false;
end;
end
else
Result:=false;
end;
end.