用 delphi写个程序把SQLserver一个表中的数据逐行写入txt文件
用delphi写个程序把SQLserver一个表中的数据转换成txt文件,读一行写一行,有人说用ado加循环写,但是我没写出来,请高手指点!!!...
用 delphi写个程序把SQLserver一个表中的数据转换成txt文件,读一行写一行,有人说用ado加循环写,但是我没写出来,请高手指点!!!
展开
1个回答
展开全部
方法比较多,就说两种先
var i,j:Integer;
s:string;
myfile:textfile;
begin
with query1 do
begin
close;
sql.clear;
sql.add('select * from sb_fcs');
open;
end;
AssignFile(myfile,'d:\2.txt');
Rewrite(myfile);
try
for i:=0 to query1.recordcount-1 do
begin
for j:=0 to query1.FieldCount-1 do
BEGIN
s:=query1.fields[j].name+':'+query1.fields[i].asstring+',';
writeln(myfile,s);//myfile 为要写的txt文件
end;
query1.next;
end;
finally CloseFile(myfile);
END;
end;
方法二:
s1:string;
s:tstringlist;
with query1 do
begin
s1:='';
for i:=0 to fieldcount-1 do s1:=s1+fields[i].asstring+' ';
s.add(s1);
循环读入
next;
end;
s.savetofile('c:\a.txt');
var i,j:Integer;
s:string;
myfile:textfile;
begin
with query1 do
begin
close;
sql.clear;
sql.add('select * from sb_fcs');
open;
end;
AssignFile(myfile,'d:\2.txt');
Rewrite(myfile);
try
for i:=0 to query1.recordcount-1 do
begin
for j:=0 to query1.FieldCount-1 do
BEGIN
s:=query1.fields[j].name+':'+query1.fields[i].asstring+',';
writeln(myfile,s);//myfile 为要写的txt文件
end;
query1.next;
end;
finally CloseFile(myfile);
END;
end;
方法二:
s1:string;
s:tstringlist;
with query1 do
begin
s1:='';
for i:=0 to fieldcount-1 do s1:=s1+fields[i].asstring+' ';
s.add(s1);
循环读入
next;
end;
s.savetofile('c:\a.txt');
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询