Connecting from Delphi Using the ODBC Data Source
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.
- Drop a TQuery, a TDatasource, and a TDBGrid component on a Delphi form.
- 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
- Set the following property for the TDatasource component:
Data Set
Set to the name of the TQuery component, or “query1” in this case
- Set the following property for the TDBGrid component:
Data Set
Set to the name of the TDatasource component, or “datasource1” in this case
- Inspect the returned results from the SELECT statement, in the DBGrid area.