Site icon Embarcadero RAD Studio, Delphi, & C++Builder Blogs

TFDBatchMove Is A Powerful Way To Move Data Between Text Files And Tables Using Datasets In Delphi

Location

You can find the TFDBatchMove sample project at:

How to Use the Sample

  1. Navigate to the location given above and open:
    • Delphi: Main.dproj
  2. Press F9 or choose Run > Run.
  3. Select one of the following connections from the Use Connection Definition drop-down menu: Access_DemoAccess_Demo_PooledSQLite_Demo or SQLite_Demo_Pooled.
  4. Click the three buttons to fully test the component behaviour:
    • Click 1. Move text to table to load the data from the Data.txt file into a table.
    • Click 2. Move table to table to move the dataset from one table to a different one.
    • Click 3. Move table to text to move the table content to an output file DataOut.txt.

Implementation

1. Move text to table button:

This button loads the content from a txt file located at Start | Programs | Embarcadero RAD Studio Sydney | SamplesObject PascalDataBaseFireDACSamplesComp LayerTFDBatchMoveMaindata.txt into a table from the selected DBMS.

The sample adds the FireDAC.Comp.BatchMove.Text unit to the interface uses section to allow the creation of a text reader TFDBatchMoveTextReader and a dataset writer TFDBatchMoveDataSetWriter.

The GuessFormat method is called before loading the data to automatically recognize the text file structure. Then the demo executes the TFDBatchMove component and shows the loaded data using a query in the TDBGrid.

2. Move table to table button:

This button moves the data between two different tables on the same DBMS.

The sample creates a TFDBatchMoveDataSetReader dataset reader and a TFDBatchMoveDataSetWriter dataset writer.

It executes the TFDBatchMove component and shows the query of both datasets on the TDBGrid.

3. Move table to text button:

This button copies the data from the table source to an output file located at the application’s path. It creates the destination file: DataOut.txt.

The sample creates a TFDBatchMoveDataSetReader dataset reader and a TFDBatchMoveTextWriter text writer.

It executes the TFDBatchMove component to create the file and save the data to the output file.

You can refer to the link below for more details about this sample:

http://docwiki.embarcadero.com/CodeExamples/Sydney/en/FireDAC.TFDBatchMove_Sample

Check out the full source code for the TFDBatchMove demo over on GitHub!

Exit mobile version