| How To Output Database Data to a CSV (Comma Separated File) |
|
Page 1 of 3
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. 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 := '';
|