荔园在线

荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀

[回到开始] [上一篇][下一篇]


发信人: zzt (少年仲永), 信区: Program
标  题: DELPHI TIPS(7)
发信站: BBS 荔园晨风站 (Fri Apr 16 18:22:25 1999), 转信

ZDTips brings you another Delphi Tip

http://www.zdtips.com -- Your #1 source for software tips and techniques
*******************************************************************

Today's sponsor:

ZD Journal's Delphi Developer's Journal
For a free issue go to
http://www.zdjournals.com/forms/ddj/cuvw79.htm
*******************************************************************

This week's Delphi Tip

Converting database tables to CSV

I like to convert my database tables to comma delimited files (CSV)
for backup and use with a spreadsheet. Use the following code:

procedure BackupTableToCSV(tableName:TTable);

var
i,j: integer; (*i-field, j-record*)
s: string; (*Record string*)
theStringList: Tstringlist; (*temp storage*)

begin
s:='';
theStringList:=TStringList.Create;
with tableName do
begin
try
Active:=True;
except
showmessage('Could not activate '+ Name);
end;
for j:=0 to (RecordCount-1) do
begin
s:='';
for i:=1 to (FieldCount-1) do
begin
(*add next field w/comma delimiter*)
s:=s+(Fields[i].AsString)+',';
end; (*i for*)
theStringList.add(s);
Next;
end; (*i for*)
theStringList.savetofile(Name+'.csv'); (*memo1.lines.*)
Showmessage(Name+ ' has been backed up.');
close;
end; (*with*)
end; (*BackupTableToCSV*)

From--Jack Darby [jdlink@eden.com], Electronic Data Systems/Austin
*******************************************************************

Tips and suggestions can be sent to

delphi_dev@zdjournals.com

We'll print your name and your e-mail or Web address, along with the tip.
*******************************************************************

This weekly tip is delivered to you as a free service from ZDTips.
To unsubscribe from a particluar tip (or tips) list go to

http://www.zdtips.com/unsub/

Type in the e-mail address and name you used to sign up for your tips and
then click unsubscribe.
*******************************************************************

ZDTips (TM) is a trademark of Ziff-Davis Inc. Copyright ?1997
Ziff-Davis Inc. All rights reserved. Reproduction in whole or in part
in any form or medium without express written permission of Ziff-Davis
is prohibited.



--



日出东方,唯我不败;
    天上地下,唯我独尊。

※ 来源:.BBS 荔园晨风站 bbs.szu.edu.cn.[FROM: 192.168.1.143]


[回到开始] [上一篇][下一篇]

荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店