这段我用来把文本导入到库里,二万行的文本记录,要7分钟才能导完。怎么回事啊。
table1是TADOtable组件。
if FileExists(Edit14.Text) then
begin
Try
TF:=TFileStream.Create(Edit14.Text,FmOpenRead);
FPos:=0;
While Tf.Position<Tf.Size do
begin
TF.ReadBuffer(ids,65); FPos:=FPos+66;
TF.Seek(FPos,0);
dstr:='';
For i:=1 to 68 do//初始化目标数组
CHids[i]:=32;
str1:='';
For i:=1 to 5 do
begin
CHIds[i]:=IDs[i];
str1:=str1 + chr(CHIds[i]);
end;
str2:='';
CHIds[6]:=IDs[6];
str2:=chr(CHIds[6]);
str3:='';
CHIds[7]:=IDs[7];
str3:=chr(CHIds[7]);
str4:='';
For i:=8 to 27 do
begin
CHIds[i]:=IDs[i];
str4:=str4+Chr(CHIds[i]);
end;
str5:='';
For i:=28 to 37 do
begin
CHIds[i]:=IDs[i];
str5:=str5+Chr(CHIds[i]);
end;
str6:='';
CHIds[38]:=IDs[38];
str6:=Chr(CHIds[38]);
str7:='';
For i:=39 to 43 do
begin
CHIds[i]:=IDs[i];
str7:=str7+Chr(CHIds[i]);
end;
str8:='';
CHIds[44]:=IDs[44];
str8:=Chr(CHIds[44]);
str9:='';
CHIds[45]:=IDs[45];
str9:=Chr(CHIds[45]);
str10:='';
BackHi:=Ord(IDs[46])*256;
BackLo:=Ord(IDs[47]);
DesStr:=IntToStr(BackHi+BackLo); Desstr:=stringofchar('0',5-length(desstr))+DesStr;
str10:=desstr; str11:='';
CHIds[51]:=IDs[48];
str11:=Chr(CHIds[51]);
str12:='';
CHIds[52]:=IDs[49];
str12:=Chr(CHIds[52]);
str13:='';
For i:=53 to 62 do
begin
CHIds[i]:=IDs[i-3];
str13:=str13+Chr(CHIds[i]);
end;
str14:='';
For i:=63 to 65 do
begin
CHIds[i]:=IDs[i-3];
str14:=str14+Chr(CHIds[i]);
end;
str15:='';
For i:=66 to 67 do
begin
CHIds[i]:=IDs[i-3];
str15:=str15+Chr(CHIds[i]);
end;
table1.Open;
table1.Append;
table1.FieldByName('songno').AsString:=str1;
table1.FieldByName('songtype').AsString:=str2;
table1.FieldByName('language').AsString:=str3;
table1.FieldByName('songname').AsString:=str4;
table1.FieldByName('singer').AsString:=str5;
table1.FieldByName('country').AsString:=str6;
table1.FieldByName('singerword').AsString:=str7;
table1.FieldByName('songcnt').AsString:=str8;
table1.FieldByName('songtone').AsString:=str9;
table1.FieldByName('beijing').AsString:=str10;
table1.FieldByName('dance').AsString:=str11;
table1.FieldByName('songmode').AsString:=str12;
table1.FieldByName('songword').AsString:=str13;
table1.FieldByName('songvol').AsString:=str14;
table1.FieldByName('songplay').AsString:=str15;
table1.Post;
end;
Except
TF.Free;
Messagebox(Form1.Handle,'导入意外中止。','提示',$40);
exit;
end;
TF.Free;
table1.Close;
table1.Open;
Messagebox(Form1.Handle,Pchar('文件已导入。'),'提示',$40);
end;
table1是TADOtable组件。
if FileExists(Edit14.Text) then
begin
Try
TF:=TFileStream.Create(Edit14.Text,FmOpenRead);
FPos:=0;
While Tf.Position<Tf.Size do
begin
TF.ReadBuffer(ids,65); FPos:=FPos+66;
TF.Seek(FPos,0);
dstr:='';
For i:=1 to 68 do//初始化目标数组
CHids[i]:=32;
str1:='';
For i:=1 to 5 do
begin
CHIds[i]:=IDs[i];
str1:=str1 + chr(CHIds[i]);
end;
str2:='';
CHIds[6]:=IDs[6];
str2:=chr(CHIds[6]);
str3:='';
CHIds[7]:=IDs[7];
str3:=chr(CHIds[7]);
str4:='';
For i:=8 to 27 do
begin
CHIds[i]:=IDs[i];
str4:=str4+Chr(CHIds[i]);
end;
str5:='';
For i:=28 to 37 do
begin
CHIds[i]:=IDs[i];
str5:=str5+Chr(CHIds[i]);
end;
str6:='';
CHIds[38]:=IDs[38];
str6:=Chr(CHIds[38]);
str7:='';
For i:=39 to 43 do
begin
CHIds[i]:=IDs[i];
str7:=str7+Chr(CHIds[i]);
end;
str8:='';
CHIds[44]:=IDs[44];
str8:=Chr(CHIds[44]);
str9:='';
CHIds[45]:=IDs[45];
str9:=Chr(CHIds[45]);
str10:='';
BackHi:=Ord(IDs[46])*256;
BackLo:=Ord(IDs[47]);
DesStr:=IntToStr(BackHi+BackLo); Desstr:=stringofchar('0',5-length(desstr))+DesStr;
str10:=desstr; str11:='';
CHIds[51]:=IDs[48];
str11:=Chr(CHIds[51]);
str12:='';
CHIds[52]:=IDs[49];
str12:=Chr(CHIds[52]);
str13:='';
For i:=53 to 62 do
begin
CHIds[i]:=IDs[i-3];
str13:=str13+Chr(CHIds[i]);
end;
str14:='';
For i:=63 to 65 do
begin
CHIds[i]:=IDs[i-3];
str14:=str14+Chr(CHIds[i]);
end;
str15:='';
For i:=66 to 67 do
begin
CHIds[i]:=IDs[i-3];
str15:=str15+Chr(CHIds[i]);
end;
table1.Open;
table1.Append;
table1.FieldByName('songno').AsString:=str1;
table1.FieldByName('songtype').AsString:=str2;
table1.FieldByName('language').AsString:=str3;
table1.FieldByName('songname').AsString:=str4;
table1.FieldByName('singer').AsString:=str5;
table1.FieldByName('country').AsString:=str6;
table1.FieldByName('singerword').AsString:=str7;
table1.FieldByName('songcnt').AsString:=str8;
table1.FieldByName('songtone').AsString:=str9;
table1.FieldByName('beijing').AsString:=str10;
table1.FieldByName('dance').AsString:=str11;
table1.FieldByName('songmode').AsString:=str12;
table1.FieldByName('songword').AsString:=str13;
table1.FieldByName('songvol').AsString:=str14;
table1.FieldByName('songplay').AsString:=str15;
table1.Post;
end;
Except
TF.Free;
Messagebox(Form1.Handle,'导入意外中止。','提示',$40);
exit;
end;
TF.Free;
table1.Close;
table1.Open;
Messagebox(Form1.Handle,Pchar('文件已导入。'),'提示',$40);
end;
lists:Tstrings; for I:=0 to LIsts.Count-1 do
begin
ADOquery1.SQL.Clear;
ADOQuery1.SQL.text:='INSERT into 表名(字段1,字段2...) values('+QuotedStr(Copy(Lists.Strings[I],a,b))+','+QuotedStr(Copy(Lists.Strings[I],a,b))+',...)';
ADOQuery1.ExecSQL;
其中的a是你要到的行中第几个字符开始,b为取a右边的几个符.