梦
梦菲斯
Unregistered / Unconfirmed
GUEST, unregistred user!
大约有15000条左右记录,导入的时候程序像死了一样,但过一段时间后看数据库,数据已经导到
数据库中了,请问应该如何优化?还有AssignFile能不能判断文本文件共有几行?
代码如下:
//导入商品综合归类数据
procedure TfrmImport.ImportComplex;
var
TextFileVar:Textfile ;
fileN:string;
sCodet,sCodes,sName,sLowRate,sHighRate,temp:string;
sRate,sMark :string;
sTableName : string;
sSql : string;
connComm : TAdoCommand ;
i : integer ;
begin
if opendialog1.execute then
begin
sTableName := 'colligation';
FileN:=opendialog1.FileName;
If FileN='' Then Exit;
AssignFile ( TextFileVar , FileN ) ;
Reset(TextFileVar);
while not SeekEof(TextFileVar) do
begin
ConnComm := TAdoCommand.Create(self);
connComm.Connection := Dm.AppConn ;
Readln(TextFileVar,temp ) ;
scodet:=copy(temp, 1,8);
sCodes:=copy(temp,9,2);
sName:=copy(temp, 17,30);
sLowRate :=copy(temp,48,5);
sHighRate :=copy(temp,54,5);
sRate := copy(temp,60,5);
sMark := copy(temp,190,1);
sSql:= 'insert into colligation(Code_t,Code_s,Ware_Name,low_rate,';
sSql:=sSql+ 'High_rate,Tax_rate,Control_Mark) values('+chr(39);
sSql:=sSql+sCodet+chr(39)+','+chr(39)+scodes+chr(39)+','+chr(39);
sSql:=sSql+sName+chr(39)+','+sLowRate+','+sHighRate+',';
sSql:=sSql+sRate+','+chr(39)+sMark+chr(39)+')';
connComm.CommandText:='';
connComm.CommandText :=sSql;
ConnComm.Execute(sSql);
end;
closeFile(TextFileVar);
ShowMessage('数据成功导入到商品综合归类表中!');
btnImport.Enabled := true ;
SB.Panels[0].Text :='数据导入成功!';
end;
end;
数据库中了,请问应该如何优化?还有AssignFile能不能判断文本文件共有几行?
代码如下:
//导入商品综合归类数据
procedure TfrmImport.ImportComplex;
var
TextFileVar:Textfile ;
fileN:string;
sCodet,sCodes,sName,sLowRate,sHighRate,temp:string;
sRate,sMark :string;
sTableName : string;
sSql : string;
connComm : TAdoCommand ;
i : integer ;
begin
if opendialog1.execute then
begin
sTableName := 'colligation';
FileN:=opendialog1.FileName;
If FileN='' Then Exit;
AssignFile ( TextFileVar , FileN ) ;
Reset(TextFileVar);
while not SeekEof(TextFileVar) do
begin
ConnComm := TAdoCommand.Create(self);
connComm.Connection := Dm.AppConn ;
Readln(TextFileVar,temp ) ;
scodet:=copy(temp, 1,8);
sCodes:=copy(temp,9,2);
sName:=copy(temp, 17,30);
sLowRate :=copy(temp,48,5);
sHighRate :=copy(temp,54,5);
sRate := copy(temp,60,5);
sMark := copy(temp,190,1);
sSql:= 'insert into colligation(Code_t,Code_s,Ware_Name,low_rate,';
sSql:=sSql+ 'High_rate,Tax_rate,Control_Mark) values('+chr(39);
sSql:=sSql+sCodet+chr(39)+','+chr(39)+scodes+chr(39)+','+chr(39);
sSql:=sSql+sName+chr(39)+','+sLowRate+','+sHighRate+',';
sSql:=sSql+sRate+','+chr(39)+sMark+chr(39)+')';
connComm.CommandText:='';
connComm.CommandText :=sSql;
ConnComm.Execute(sSql);
end;
closeFile(TextFileVar);
ShowMessage('数据成功导入到商品综合归类表中!');
btnImport.Enabled := true ;
SB.Panels[0].Text :='数据导入成功!';
end;
end;