procedure TForm1.Button1Click(Sender: TObject);
var
i,row:integer;
s:Tstringlist;
begin
if SaveDialog1.Execute then
begin
s:=Tstringlist.create;
s.lines.add('');
Screen.Cursor:=crHourGlass;
if not adoQuery1.Active then
begin
adoQuery1.Open;
end;
while not adoQuery1.Eofdo
begin
for i:=0 to adoQuery1.Fields.Count-1do
begin
s.lines[0]:=s.lines[0]+adoquery1.fields.fieldname+':'+adoQuery1.Fields.AsString+#13+#10;
end;
adoQuery1.Next;
end;
s.savetofile(SaveDialog1.FileName);
Screen.Cursor:=crDefault;
Application.MessageBox('Export successfully!','Information',0);
end;
end;
var
i,row:integer;
s:Tstringlist;
tmp:string;
begin
s:=tstringlist.create;
try
tmp:='';
query1.close;
query1.sql.text:='select* from table';
query1.open;
for i:=0 to query1.fields.count-1do
tmp:=tmp+query1.fields.fieldname;
s.add(tmp);
query1.first;
while not query1.eofdo
begin
for i:=0 to query1.fields.count-1do
s.add(query1.fields.asstring);
query1.next;
end;
s.savetofile(filename);
finally
s.free;
end;
end;
最干脆的就是直接写文件:俺就是用这作为写日志的 过程在程序中调用。
var
F:TextFile;
begin
AssignFile(F,'Test.Text');
try
if not Exists('Test.Text') then
begin
ReWrite(F);
Append(F);
end;
Table1.First;
while not Table1.Eofdo
begin
Append(F);
Writele(F,字段1.Value,字段2.Value,....);
Table1.Next;
end;
finally
CloseFile(F);
end;
end;