Importing Delimited Data
Go Up to Exporting and Importing Delimited Data
To import delimited data, you will need TIBSQL
, TIBDatabase
, and TIBTransaction
components.et up the database component, and associate the components with each other. In the following example, the database and transaction components are set to active in the code.
- Tip: Use the Database Editor to set up the database component. To start the Database Editor, right click the database component with the mouse and select Database Editor from the drop-down menu.
It is important to note that you must import data into a table with the same column definitions and data types, and in the same order; otherwise, all sorts of unpredictable and undesirable results may occur.
The following code snippet inputs selected data with a SQL INSERT
statement from the source_delim
file created in the last example into the DESTINATION
table.
procedure TForm1.Button4Click(Sender: TObject); var DelimInput : TIBInputDelimitedFile; begin IBSQL4.Database.Open; IBSQL4.Transaction.StartTransaction; IBSQL4.SQL.Text := 'Insert into Destination values(:name, :number, :hired)'; DelimInput := TIBInputDelimitedFile.Create; try DelimInput.Filename := 'source_delim'; IBSQL4.BatchInput(DelimInput); finally DelimInput.Free; IBSQL4.Transaction.Commit; end; end;