如题:
数据表table1,其关键字字段为ID1,用线程向里面添加记录,线程exe方法为:procedure mythread.Execute;
var
adods:TADODataSet;
begin
{ Place thread code here } Coinitialize(nil); if Application.MessageBox('确实要导入吗?','提示信息',MB_OKCANCEL)=ID_OK then
begin
with DM.ADODS_Export do
begin
Close;CommandText:='select * from table1';
Open;
end;
while not DM.ADODS_Export.Eof do
begin
dm.ADOComm_Import.CommandText:='insert into table2(id,zd1,zd2)'+
' values(:pid,:pzd1,:pzd2)';
DM.ADOComm_Import.Parameters.ParamByName('pid').Value:=DM.adods_export.fieldbyname('id').asstring;
DM.ADOComm_Import.Parameters.ParamByName('pzd1').Value:=DM.ADODS_Export.fieldbyname('zd1').AsString;
DM.ADOComm_Import.Parameters.ParamByName('zi').Value:=DM.ADODS_Export.fieldbyname('zd2').AsString;;
dm.ADOComm_Import.Execute;
DM.ADODS_Export.Next;
end;
end;
end;在运行的时候,我想中止线程,然后结束线程,关闭窗体的时候提示"在异步运行时,操作不能被执行",怎么办,高手救命,求解!!!!!!!
数据表table1,其关键字字段为ID1,用线程向里面添加记录,线程exe方法为:procedure mythread.Execute;
var
adods:TADODataSet;
begin
{ Place thread code here } Coinitialize(nil); if Application.MessageBox('确实要导入吗?','提示信息',MB_OKCANCEL)=ID_OK then
begin
with DM.ADODS_Export do
begin
Close;CommandText:='select * from table1';
Open;
end;
while not DM.ADODS_Export.Eof do
begin
dm.ADOComm_Import.CommandText:='insert into table2(id,zd1,zd2)'+
' values(:pid,:pzd1,:pzd2)';
DM.ADOComm_Import.Parameters.ParamByName('pid').Value:=DM.adods_export.fieldbyname('id').asstring;
DM.ADOComm_Import.Parameters.ParamByName('pzd1').Value:=DM.ADODS_Export.fieldbyname('zd1').AsString;
DM.ADOComm_Import.Parameters.ParamByName('zi').Value:=DM.ADODS_Export.fieldbyname('zd2').AsString;;
dm.ADOComm_Import.Execute;
DM.ADODS_Export.Next;
end;
end;
end;在运行的时候,我想中止线程,然后结束线程,关闭窗体的时候提示"在异步运行时,操作不能被执行",怎么办,高手救命,求解!!!!!!!
中止线程代码是:
if ThdImport<>nil then
begin
ThdImport.Suspend;
ThdImport.Terminate;
end;
dm.ADOComm_Import.Execute;
DM.ADODS_Export.Next;
sleep(10);//加这句
end;
......
1、在线程中使用独立的数据链接。
2、在代码中作以下修改
//while not DM.ADODS_Export.Eof do
while (not Terminated) and (not DM.ADODS_Export.Eof) do
3、停止线程时直接执行ThdImport.Terminate。
dm.ADOComm_Import.Execute;
sleep(10);//加这句
if terminated then
break;
DM.ADODS_Export.Next;
end;
......你线程释放代码没有?
procedure mythread.Execute;
var
adods:TADODataSet;
begin
{ Place thread code here }
inherited;
FreeOnTerminate:=True;
Coinitialize(nil);
。。
begin
Close;CommandText:='select * from table1';
Open;
end;
中table1表里的数据有100万行,我怀疑在打开数据集的时候,即执行open的时候出现问题了,因为open的时候会有几秒的时间的,怎样在数据集正在打开的时候中止呢?
数据集正在打开的时候好像没办法中止
begin
try
while ( GetProductUrl() ) and (not Terminated) do
begin
GetProduce();
if not Fisone then
PostinAccess()
else
PostProduct();
。
。
。 end;
except end;
end;
在你的例子中很明白就是线程结束要等数据库操作结束,假如你线程正好执行到SELECT几百万条记录的时候,去结束线程,肯定就会报这个错误了,居然还说数据集是否打开没有意义,如果你是等到数据集打开之后去结束线程,而且在循环里加了如果线程结束就跳出的代码,就不会有问题,你还是SELECT *,说实话,可能不是几秒能打开的吧?把你线程的代码都贴出来,并且说下你的目地