数据导入(30分)

  • 主题发起人 主题发起人 wangqinyun2000
  • 开始时间 开始时间
W

wangqinyun2000

Unregistered / Unconfirmed
GUEST, unregistred user!
表ADOQ61 为保存数据<br>表ADOQ62 存放表ADOQ61字段信息有字段名,字段类型等!!<br>表ADOQ63 读ELS文件内容<br><br>XLS文件三万多记录,导入数据要十多分钟,能不能帮提些速啊<br><br>高手帮帮忙啊,主要代码如下:<br>procedure TForm6.RzButton1Click(Sender: TObject);<br>var<br>&nbsp;fs3,res1,res2,res3:string;<br>&nbsp;rei1:integer;<br>begin<br>fs3:='';<br>fs3:='select * from fname1 where TABNAME='+#39+fs1+#39;<br>with DataModule17 do<br>begin<br>&nbsp; &nbsp;ADOQ63.SQL.Clear;<br>&nbsp; &nbsp;ADOQ63.Close;<br>&nbsp; &nbsp;ADOQ63.SQL.Add(fs3);<br>&nbsp; &nbsp;ADOQ63.Open;<br>&nbsp; &nbsp;ADOQ62.First;<br>&nbsp; &nbsp;while not (ADOQ62.Eof) &nbsp;do<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; ADOQ61.Append;<br>&nbsp; &nbsp; &nbsp; ADOQ63.First;<br>&nbsp; &nbsp; &nbsp; while not(ADOQ63.Eof) do<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;res1:=trim(ADOQ63.FieldByName('FNAME').Value);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;rei1:=ADOQ63.FieldByName('EXCELNO').Value-1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;res2:=trim(copy(ADOQ63.FieldByName('bak').Value,1,1));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if res2='C' then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ADOQ61.FieldByName(res1).AsString:=trim(ADOQ62.fields[rei1].AsString);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if res2='D' then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IF trim(ADOQ62.fields[rei1].asstring)&lt;&gt;'' THEN ADOQ61.FieldByName(res1).AsDateTime:=ADOQ62.fields[rei1].AsDateTime;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if res2='N' then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;res3:=TRIM(ADOQ62.fields[rei1].AsString);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if res3='' then res3:='0';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ADOQ61.FieldByName(res1).AsFloat:=STRTOFLOAT(trim(res3));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ADOQ63.Next;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp;ADOQ61.FieldByName('SYSDATA').AsDateTime:=Rzdatetimeedit1.Date;<br>&nbsp; &nbsp; &nbsp;ADOQ61.FieldByName('DCDATA').AsDateTime:=Rzdatetimeedit1.Date;<br>&nbsp; &nbsp; &nbsp;ADOQ61.POST;<br>&nbsp; &nbsp; &nbsp;ADOQ62.Next;<br>&nbsp; &nbsp;// &nbsp;Application.MessageBox('4', '矗ボ', MB_ICONINFORMATION);<br>&nbsp; &nbsp;end;<br>END;<br>end;
 
可以.就是用SQL语句会快一些而已
 
如果字段都对得上的话可对直接用SQL语句来导,论坛上就有例子,可参考如下网页。<br>http://www.delphibbs.com/delphibbs/dispq.asp?lid=1691966<br>如果不同,需要先读出,再根据条件来导的话,建议进行如下操作会快一点。<br>&nbsp; DataSet.DisableControls;<br>&nbsp; try<br>&nbsp; &nbsp; //进行导入工作<br>&nbsp; finally<br>&nbsp; &nbsp; DataSet.EnableControls;<br>&nbsp; end;<br>还有就是建议不要每一次APPEND都进行数据库交互工作,建议将所有的插入操作都扔到一个事务中,最后一起进行提交,这样速度也会加快一些。。。
 
呵呵 是啊,楼上的说得很好很详细<br>其实 可以直接不使用数据感知控件,直接在dateset中操作。<br>再或者使用SQL Server的DTS 生成代码,直接写道你的程序中,速度最快
 
採用lngdtommy的方法,三萬條只要3分?啊<br><br>ADOQ61采用ADODataSet替換!!!!<br><br>收貼
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
512
import
I
I
回复
0
查看
604
import
I
后退
顶部