TimCS.Co.Uk Delphi Delphi Guides How To Output Database Data to a CSV (Comma Separated File)
How To Output Database Data to a CSV (Comma Separated File)

 

To start this project , three main variables need to be declared , the first is a TStringlist which will hold all of the records from the database and the field names in a comma separated format. The second is an integer field used with the loops to navigate through the database. Finally the third is a string variable to hold the field names separated by a comma.

To declare these variables type as follows either in a procedure,function or as part of the main form as follows :


Code:
var
ExportCsvData      : TStringList;
ReportFieldCounter : Integer;
ReportFieldNames   : String;


The String and the TStringlist need initializing however each are done differently. This method can only been done within a procedure or a function. To initialize the TStringlist variable type the following:
Code:
ExportCsvData := TStringList.create;

To initialize the string type the following:

Code:
ReportFieldNames := '';


 

Powered by Joomla!. Valid XHTML and CSS. Credits go to Gareth Flowers for his help with this site.