Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Output dataset to CSV file

379 views
Skip to first unread message

Glyn Davies

unread,
Jul 9, 2002, 8:33:36 AM7/9/02
to
How do I export the data in a ClientDataSet to an ASCII CSV file?

All help gratefully received

Glyn

Bill Todd

unread,
Jul 9, 2002, 10:10:03 AM7/9/02
to
Something like the following.

procedure dgExportTableDelimited(
DataSet: TDataSet;
AsciiFilePath: String;
Delimiter, Separator: Char);
{Exports a dataset as a delimited text file.
Parameters:
DataSet: The data to be exported.
AsciiFilePath: The text file path and name.
Delimiter: The character placed around non-
numeric field values, usually a
double quotation mark.
Separator: The character placed between
fields, usually a comma.
}
var
AsciiFile: System.Text;
I: Integer;
LastField: Integer;
begin
Assign(AsciiFile, AsciiFilePath);
Rewrite(AsciiFile);
LastField := DataSet.FieldCount - 1;
while not DataSet.EOF do
begin
for I := 0 to LastField do
begin
{If the field is not numeric write the opening
delimiter character.}
if not (DataSet.Fields[I].DataType in
[ftBCD, ftCurrency, ftFloat, ftInteger, ftSmallInt, ftWord])
then
Write(AsciiFile, Delimiter);
{Write the field value.}
Write(AsciiFile, DataSet.Fields[I].AsString);
{If the field type is not numeric write the
closing delimiter character.}
if not (DataSet.Fields[I].DataType in
[ftBCD, ftCurrency, ftFloat, ftInteger, ftSmallInt, ftWord])
then
Write(AsciiFile, Delimiter);
{If this is not the last field write the
separator character.}
if I < LastField then
Write(AsciiFile, Separator);
end; {for}
{Write the carriage/line feed at the end of
this record.}
Writeln(AsciiFile, '');
DataSet.Next;
end; {while}
System.Close(AsciiFile);
end;


--
Bill (TeamB)
(TeamB cannot respond to questions received via email)

Thomas Miller

unread,
Jul 9, 2002, 4:42:20 PM7/9/02
to
You might want to try TSQLDatapump

http://sourceforge.net/projects/dbexpressplus

or our website.


--
Thomas Miller
Delphi Client/Server Certified Developer
BSS Accounting & Distribution Software
BSS Enterprise Accounting FrameWork

http://www.bss-software.com

Mike Shkolnik

unread,
Jul 10, 2002, 4:21:08 AM7/10/02
to
Check SMExport suite (www.scalabium.com/sme).

There a lot of file formats are supported including CSV/TXT, MS Excel,
HTML/XML, MS Word, MS Access, Lotus, ...

And you can export your any dataset (TClientDataset too, of course) in a few
mouse clicks...

--
With best regards, Mike Shkolnik
E-Mail: mshk...@scalabium.com
WEB: http://www.scalabium.com

Glyn Davies <gl...@cirrus.co.za> пишет в
сообщении:Xns92469427B52...@207.105.83.65...

Glyn Davies

unread,
Jul 15, 2002, 10:28:11 AM7/15/02
to
Thomas Miller <tmi...@bss-software.com> wrote in news:3D2B4AAC.1050808@bss-
software.com:

> You might want to try TSQLDatapump
>
> http://sourceforge.net/projects/dbexpressplus
>
> or our website.

I have tried it but as far as I can see it does not support writing to an
ASCII file. Has this changed?

Ross Davis

unread,
Jul 15, 2002, 10:47:36 AM7/15/02
to
you could also take a look at kbmmemtable from www.components4developers.com
I works very well and is free as well. You just have to do a
loadfromdataset to move the data from your table to the memtable, but this
is fast.

"Glyn Davies" <gl...@cirrus.co.za> wrote in message
news:Xns924CA791F342...@207.105.83.65...

0 new messages