Connecting from Delphi Using the ODBC Data Source

From InterBase
Jump to: navigation, search

Go Up to Configuring and Using ODBC Data Sources


ODBC connection from Delphi is very similar to connecting using BDE from Delphi.

The following example shows connecting using the TQuery component, and also displaying the results of an SQL statement.

  1. Drop a TQuery, a TDatasource, and a TDBGrid component on a Delphi form.
  2. Set the following properties for the TQuery component:

    DatabaseName

    Pick from the list the data source name created using ODBC Administrator

    SQL

    enter the SQL statement to be executed; for example, “SELECT * FROM Table1”

    Active

    Set to True to connect; supply user name and password on connection

  3. Set the following property for the TDatasource component:

    Data Set

    Set to the name of the TQuery component, or “query1” in this case

  4. Set the following property for the TDBGrid component:

    Data Set

    Set to the name of the TDatasource component, or “datasource1” in this case

  5. Inspect the returned results from the SELECT statement, in the DBGrid area.