关于导出数据的问题?(100分)

  • 主题发起人 主题发起人 hhdj
  • 开始时间 开始时间
H

hhdj

Unregistered / Unconfirmed
GUEST, unregistred user!
将一个结果集ADOQuery中的数据导到一个文本文件中?谢谢
 
adoquery.savetofile('abc.txt')
 
To dhl2001:

I used adoQuery1.saveToFile('abc.txt') to create the output text file, but there
is some wrong text in the file. Why?

Thanks.
 
1. I have checked the help, and it seems that ADO saveToFile only supports the
format of XML and ADTG(Advanced Data Table Gram, a proprietary Microsoft format).
Therefore, you probably can't use saveToFile directly.

2. There is a previous example using TStringList for outputing ADO data to text
file. Based on that, I have a sample as below (Note: the table has 2 field
Name,Capital, and the output text file is delimited with character:???):

procedure TForm4.Button1Click(Sender: TObject);
var
TSL: TStringList;
s,name,capital:string;
begin
adoTable1.Active:=true;
adoTable1.Open;

TSL:=TStringList.Create;
while not adoTable1.Eof do
Begin
name:=adoTable1.FieldbyName('name').AsString;
capital:=adoTable1.FieldbyName('capital').AsString;
s:=name+'???'+capital;
TSL.Add(s);
adoTable1.Next;
End;
TSL.SaveToFile('test.txt');
TSL.Free;
end;
 
你用tdxdbgrid来显示adoquery中的数据,然后用tdxdbgrid来导出应该可以的。
 
后退
顶部