Y
yecloudy
Unregistered / Unconfirmed
GUEST, unregistred user!
线程中动态生成ADODataSet和ADOConnection,但出错:'can not perform thisoperartor on a closed dataset‘ ,请救命啊,在线等。(0分)<br />下面是在线程中动态生成ADODataSet和ADOConnection,但出错:'can not perform this
operartor on a closed dataset ',请救命啊,在线等。
unit InsData;
interface
uses
Classes, ADODB,ActiveX,StrUtils,SysUtils;
type
TInsertDataThread = class(TThread)
private
{ Private declarations }
protected
ADODataSet: TADODataSet;
// ADOCommand: TADOCommand;
ADOConnection: TADOConnection;
Ip,Name,Size,Time,DirName,TxtName:Ansistring;
F:TextFile;
procedure Execute; override;
procedure AnalyzeDir(line:AnsiString);
procedure AnalyzeTxt(line:AnsiString);
public
constructor create(Sfilename:Ansistring);
Destructor Destroy;override;
end;
implementation
constructor TInsertDatathread.create(SFileName:AnsiString);
begin
inherited Create(true);
freeonterminate:=true;
CoInitialize(Nil);
ADOConnection := TADOConnection.Create( nil );
ADODataSet:= TADODataSet.Create(nil);
with AdoConnection do
begin
Provider := 'Provider=SQLOLEDB.1';
LoginPrompt := False;
KeepConnection := True;
ConnectionString := 'Provider=SQLOLEDB.1;Password=。。;Persist Security Info=True;User ID=。。;Initial Catalog=ftp;Data Source=。。';
end;
with AdoDataSet do
begin
Connection:=AdoConnection;
CacheSize:=1000;
locktype:=ltBatchOptimistic;
end;
ip:=SFileName;
Resume;
end;
Destructor TInsertDataThread.Destroy;
begin
ADOConnection.Free;
ADOConnection:=nil;
ADODataSet.Free;
ADODataSet:=nil;
CoUninitialize;
end;
procedure TInsertDataThread.Execute;
var
FileItem:string;
begin
DirName:=ip+'dir.txt';
txtName:=ip+'txt.txt';
if FIleExists(Dirname) then
begin
Assignfile(F,DirName);
Reset(F);
try
begin
while not Eof(f) do
begin
Readln(F,FileItem);
with ADODataSet do
begin
CommandText:='insert into allml(name,time,ip)'
+'values name,:time,:ip)';
Parameters.ParamByName('name').Value :=name;
Parameters.ParamByName('time').Value :=time;
Parameters.ParamByName('ip').Value :=ip;
end;
end;
end;
finally
closefile(f);
end;
end
else if FIleExists(txtname) then
begin
Assignfile(F,txtName);
Reset(F);
try
begin
while not Eof(f) do
begin
Readln(F,FileItem);
AnalyzeTxt(FileItem);
with ADODataSet do
begin
CommandText:='insert into allfile(name,time,size,ip)'
+'values name,:time,:size,:ip)';
Parameters.ParamByName('name').Value :=name;
Parameters.ParamByName('time').Value :=time;
Parameters.ParamByName('size').Value :=size;
Parameters.ParamByName('ip').Value :=ip;
//execute
end;
end;
end;
finally
closefile(f);
end;
end;
AdoDataSet.UpdateBatch(arall);
end;
operartor on a closed dataset ',请救命啊,在线等。
unit InsData;
interface
uses
Classes, ADODB,ActiveX,StrUtils,SysUtils;
type
TInsertDataThread = class(TThread)
private
{ Private declarations }
protected
ADODataSet: TADODataSet;
// ADOCommand: TADOCommand;
ADOConnection: TADOConnection;
Ip,Name,Size,Time,DirName,TxtName:Ansistring;
F:TextFile;
procedure Execute; override;
procedure AnalyzeDir(line:AnsiString);
procedure AnalyzeTxt(line:AnsiString);
public
constructor create(Sfilename:Ansistring);
Destructor Destroy;override;
end;
implementation
constructor TInsertDatathread.create(SFileName:AnsiString);
begin
inherited Create(true);
freeonterminate:=true;
CoInitialize(Nil);
ADOConnection := TADOConnection.Create( nil );
ADODataSet:= TADODataSet.Create(nil);
with AdoConnection do
begin
Provider := 'Provider=SQLOLEDB.1';
LoginPrompt := False;
KeepConnection := True;
ConnectionString := 'Provider=SQLOLEDB.1;Password=。。;Persist Security Info=True;User ID=。。;Initial Catalog=ftp;Data Source=。。';
end;
with AdoDataSet do
begin
Connection:=AdoConnection;
CacheSize:=1000;
locktype:=ltBatchOptimistic;
end;
ip:=SFileName;
Resume;
end;
Destructor TInsertDataThread.Destroy;
begin
ADOConnection.Free;
ADOConnection:=nil;
ADODataSet.Free;
ADODataSet:=nil;
CoUninitialize;
end;
procedure TInsertDataThread.Execute;
var
FileItem:string;
begin
DirName:=ip+'dir.txt';
txtName:=ip+'txt.txt';
if FIleExists(Dirname) then
begin
Assignfile(F,DirName);
Reset(F);
try
begin
while not Eof(f) do
begin
Readln(F,FileItem);
with ADODataSet do
begin
CommandText:='insert into allml(name,time,ip)'
+'values name,:time,:ip)';
Parameters.ParamByName('name').Value :=name;
Parameters.ParamByName('time').Value :=time;
Parameters.ParamByName('ip').Value :=ip;
end;
end;
end;
finally
closefile(f);
end;
end
else if FIleExists(txtname) then
begin
Assignfile(F,txtName);
Reset(F);
try
begin
while not Eof(f) do
begin
Readln(F,FileItem);
AnalyzeTxt(FileItem);
with ADODataSet do
begin
CommandText:='insert into allfile(name,time,size,ip)'
+'values name,:time,:size,:ip)';
Parameters.ParamByName('name').Value :=name;
Parameters.ParamByName('time').Value :=time;
Parameters.ParamByName('size').Value :=size;
Parameters.ParamByName('ip').Value :=ip;
//execute
end;
end;
end;
finally
closefile(f);
end;
end;
AdoDataSet.UpdateBatch(arall);
end;