logo
small logo
  • Products
  • Buy
  • Support
  • About
  • Customer panel Support
    • en
    • de
    • JP
    • ZH
  • Home
  • /
  • Articles
  • /
  • How to connect a CSV file as a DataSet in Delphi
  • Turn database data into a document in Delphi / Lazarus / C++ Builder

    February 3, 2021

    How to make a mush of data into an informative report? Oracle DB, MySQL, Microsoft SQL

    read more
  • How to create one single report out of several in Delphi / Lazarus / C++ Builder

    December 11, 2020

    I would like to note that FastReport VCL is one of the most convenient components

    read more
  • How to create a file in CSV format from Delphi / C++Builder / Lazarus application?

    May 29, 2020

    CSV files (comma-separated values) are special types of files that you can create, read and

    read more
  • How to generate ITF (interleaved, industrial, matrix) barcode with Delphi / Lazarus / C ++ Builder

    November 11, 2020

    A bit of theory about barcodes It is difficult to imagine our life without barcodes, especially

    read more
  • Installing FastReport in Lazarus

    March 17, 2021

    This article is outdated. Updated information is available at the following link. As part of the

    read more

How to connect a CSV file as a DataSet in Delphi

May 12, 2020

Probably many have encountered the problem of using a CSV file as a DataSet in Delphi.

Let's have a look at  one of the solutions to this problem. We will connect the CSV file via TADOQuery and build a report from this data in FastReport VCL.

Create a project and add the following components.

1
2
3
4
5
6
7
8
OHLC_Query: TADOQuery;
OHLC_Source: TDataSource;
OHLC_DB: TfrxDBDataset;
frxReport1: TfrxReport;
frxDesigner1: TfrxDesigner; 
frxChartObject1: TfrxChartObject;
ButtonShowReport: TButton;
ButtonDesignReport: TButton;

 

To connect to the CSV file, we will use the OHLC_Query: TADOQuery component.

Set it up by setting the ConnectionString property:

1
OHLC_Query.ConnectionString :=’Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\;Extended Properties="text;";Persist Security Info=False’

Next, you will also need to write your Schema.ini file in accordance with the documentation on the Microsoft website:

https://docs.microsoft.com/en-us/sql/odbc/microsoft/schema-ini-file-text-file-driver?view=sql-server-ver15

And add it to the project folder.

Let's analyze the example of our demo CSV file (EURUSD_200201_200410.csv), it has the following structure:

Data is separated using the “;”

The data is presented in a more visual form, they have 9 columns:

Let's create a text file and save it as schema.ini

This file should have the following structure according to the documentation on the Microsoft website:

https://docs.microsoft.com/en-us/sql/odbc/microsoft/schema-ini-file-text-file-driver?view=sql-server-ver15

schema.ini
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[EURUSD_200201_200410.csv]
ColNameHeader=True 
Format=Delimited(;) 
DecimalSymbol=.
TextDelimiter='
CharacterSet=ANSI 
DateTimeFormat=yyyymmdd
Col1=TICKER char
Col2=PER integer 
Col3=DATE date 
Col4=TIME char
Col5=OPEN float
Col6=HIGH float 
Col7=LOW float
Col8=CLOSE float
Col9=VOL integer

Set the necessary settings for OHLC_Source and OHLC_DB:

1
2
3
OHLC_Source.DataSet := OHLC_Query;
OHLC_DB.DataSource := OHLC_Source;
OHLC_DB.UserName := 'OHLC';

Create a template and save it as DemoCSV.fr3

Design DemoCSV.fr3

And connect the DataSet to the template

   

Next, add the ButtonDesignReportClick, ButtonShowReportClick, and FormCreate events:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
procedure TFormDemoCSV.ButtonDesignReportClick(Sender: TObject);
begin
 frxReport1.DesignReport;
end;
 
procedure TFormDemoCSV.ButtonShowReportClick(Sender: TObject);
begin
 frxReport1.ShowReport();
end;
 
procedure TFormDemoCSV.FormCreate(Sender: TObject);
begin
 frxReport1.LoadFromFile('./DemoCSV.fr3')
end;

Launch applications

When you click on the ButtonShowReport button, a report is built.

Congratulations, you included the CSV file as a DataSet in Delphi and built a report from this data in FastReport VCL!

Download link: DemoCSV.zip

about product buy
avatar
Alexander Syrykh
QA
Fast Reports Team: Alexander Syrykh - Quality Assurance at Fast Reports
VCL FastReport CSV Data Source Delphi

Add comment
logo
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • info@fast-report.com
  • 901 N Pitt Str #325 Alexandria VA 22314
  • Buy
  • Download
  • Documentation
  • Testimonials
  • How to uninstall
  • FAQ
  • Tutorial Video
  • Forum
  • Support SLA
  • Articles
  • Our News
  • Press about us
  • Resellers
  • Extended licensing
  • Contact us

© 1998-2023 by Fast Reports Inc.

  • Privacy Policy

Trustpilot