例:
将 11.txt 文件(其内容是:10902003100801
10902003100802
10902003100803
10902003100804
10902003100805
10902003100806 导入SQL7中TEXT 内的T1 表的POTXT 字段中
将 11.txt 文件(其内容是:10902003100801
10902003100802
10902003100803
10902003100804
10902003100805
10902003100806 导入SQL7中TEXT 内的T1 表的POTXT 字段中
Function txtToSQLServer(txtfilename: string): boolean;
var
adoCon : TADOConnection;
adoQuery : TADOQuery;
txtSourceFile : TextFile;
begin
result := False;
if Not FileExists(txtfilename) then exit;
try
assignfile(txtSourceFile,txtfilename);
Reset(txtSourceFile);
if Eof(txtSourceFile) then exit;
adoCon := TADOConnection.Create;
adoQuery := TADOQuery.Create(nil);
try
With adoCon do
begin
ConnectionString := 'DRIVER={SQL SERVER};SERVER=ERPSERVER;UID=sa;PWD=;Database=TEST';
Connected := True;
end;
With adoQuery do
begin
Connection := adoCon;
end;
except
on E:Exception do
showmessage(E.Message);
end;
while not eof(txtSourceFile) do
begin
With adoQuery do
begin
sql.clear;
sql.add('insert into t1(kqno) values (' + quotedstr(readln(txtSourceFile) + ')');
ExecSQL;
end;
end;
result := true;
finally
adoCon.close;
adoQuery.free;
adoCon.free;
end;
end;