能否给点分 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;
告诉你一个最快的方法,用SQLServer连接DBF 在SQLServer中执行 SELECT * into bmk FROM 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>$]
比如txt文件在c:\temp\aaaa.txt
就执行
ADOConnection.Connected := True;
ADOConnection.Execute(’Select * Into abcd From [Text;Database=c:\temp].aaaa.txt’);
http://www.envanet.com
我的论坛,这样说是不是有拉条皮的嫌疑
不过我确实放了很多高程考试的资料在上面
好的话,给点分支持一下
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;
在SQLServer中执行
SELECT * into bmk
FROM 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>$]