本文整理自网络,侵删。
在Form上放一个ADOConnection,连结指向目标Access库比如txt文件在c:\temp\aaaa.txt就执行ADOConnection.Connected := True;ADOConnection.Execute(’Select * Into abcd From [Text;Database=c:\temp].aaaa.txt’);
方法2:procedure TForm1.btnimporttextClick(Sender: TObject);var TextFileVar: Textfile ; fileN,s: string; testcode,name,school,grade,temp:string; num:integer;begin num:=0; if opendialog1.execute then begin FileN:=opendialog1.FileName; If FileN='|' Then Exit; AssignFile ( TextFileVar , FileN ) ; Reset(TextFileVar); memo1.Lines.LoadFromFile(opendialog1.FileName); if messagedlg('确定要将该文本导入数据库吗?',mtconfirmation,[mbyes,mbno],0)=mryes then begin while not SeekEof(TextFileVar) do begin Readln ( TextFileVar , temp ) ; if pos('|',temp)>0 then begin testcode:=copy(temp, 1, pos('|',temp)-1); temp:=copy(temp,pos('|',temp)+1,length(temp)-pos('|',temp)); name:=copy(temp, 1, pos('|',temp)-1); temp:=copy(temp,pos('|',temp)+1,length(temp)-pos('|',temp)); school:=copy(temp, 1, pos('|',temp)-1); temp:=copy(temp,pos('|',temp)+1,length(temp)-pos('|',temp)); grade:=copy(temp, 1, pos('|',temp)-1); adoquery1.Close; adoquery1.SQL.Clear; adoquery1.SQL.Add('select testcode from pystudent where testcode='+testcode); adoquery1.Open; if adoquery1.RecordCount=0 then begin adotable1.Open; adotable1.insert; adotable1.fields[0].AsString:=testcode; adotable1.fields[1].AsString:=name; adotable1.fields[2].AsString:=school; adotable1.Fields[3].AsString:=grade; adotable1.post; end else num:=num+1; adoquery1.Close; s:=inttostr(num); end; end; showmessage('有'+s+'条记录相同而未导入数据库'); closeFile(TextFileVar); adotable1.Close; showmessage('有效文件成功导入数据库'); end; end;
方法3:告诉你一个最快的方法,用SQLServer连接DBF在SQLServer中执行SELECT * into bmkFROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0', 'Data Source="e:\share";User ID=Admin;Password=;Extended properties=dBase 5.0')...bmk这样就可以把e:\share中的bmk.dbf表导入到Sqlserver中,速度是最快的把压箱底的方法都告诉大家在Form上放一个ADOConnection,连结指向目标Access库比如txt文件在c:\temp\aaaa.txt就执行ADOConnection.Connected := True;ADOConnection.Execute('Select * Into abcd From [Text;Database=c:\temp].aaaa.txt');就一切Ok了,这个方法一定行的,我好不容易才研究出来的有了这两个例子,异构数据库之间导数据的问题就举一反三,迎刃而解了。
把Excel导入到Access中,同txt类似select * into <table name> from [excel 8.0;database=<filename>].[<sheetname>$]
来源:https://bbs.csdn.net/topics/30361870?locationNum=15&fps=1
相关阅读 >>
Delphi firedac tfdconnection连接mysql数据库
Delphi 简化版的inputquery 中文版输入对话框
更多相关阅读请进入《Delphi》频道 >>