Tutorial
This tutorial illustrates how to connect to a data source, create a table and insert values into it, retrieve those values, and disconnect from the data source. In so doing, it acquaints you with most of the ODBC Test user interface.
To connect to a data source
-
Create a dBASE data source called Test Data using the ODBC Administrator. (For information about creating data sources with the ODBC Administrator, see "Managing Data Sources" under "Microsoft ODBC Data Source Administrator."
-
Start ODBC Test. Click Start, point to Programs, point to MS Data Access SDK 2.0, and select ODBC Test or click Start, click Run, and type \Bin\Odbc\ODBCte32.exe.
-
From the Conn menu, choose Full Connect. ODBC Test displays the Full Connect dialog box.
-
Select Test Data from the list of data sources and click OK. ODBC Test connects to the Test Data data source and allocates a statement handle. It displays the connection window and the allocated statement handle in the statement handle list.
To create a table and insert values into it
-
Using the connection window from the previous procedure, type the following SQL statement in the input window:
CREATE TABLE NewTable (City CHAR(10), State CHAR(2))
-
From the Stmt menu, choose SQLExecDirect. ODBC Test displays the SQLExecDirect dialog box. The value of <input window> in the StatementText argument indicates that ODBC Test will retrieve the SQL statement from the input window.
-
Click OK to execute SQLExecDirect. ODBC Test calls SQLExecDirect with the specified arguments and displays the function name, input argument values, and return code in the output window.
-
Type the following SQL statements in the input window. You do not need to delete the CREATE TABLE statement.
INSERT INTO NewTable VALUES ('Erie', 'PA')
INSERT INTO NewTable VALUES ('Atlanta', 'GA')
INSERT INTO NewTable VALUES ('Cheyenne', 'WY')
-
Select the first INSERT statement.
-
From the Stmt menu, choose SQLExecDirect again, then click OK to execute SQLExecDirect with the new arguments. ODBC Test calls the driver to insert the values in the table and displays information about the function call in the output window.
Note If you don't select the line you want to execute, ODBC Test passes all the statements in the input window to the driver. Although some drivers can process multiple statements, the dBASE driver used in this example cannot.
-
Repeat steps 5 and 6 for the other two INSERT statements.
To retrieve data from a table
-
Using the connection window and the table from the previous procedure, type the following SQL statement in the input window and select it:
SELECT * FROM NewTable
-
From the Stmt menu, choose SQLExecDirect again, then click OK to execute SQLExecDirect with the new arguments. ODBC Test calls the driver to select the data from the table and displays information about the function call in the output window.
-
From the Results menu, select the Get Data All function tool. This tool retrieves all of the data in the result set created by the SELECT statement. It displays the column count, the column names, the data, and the number of rows fetched in the output window:
"CITY", "STATE"
"Erie", "PA"
"Atlanta", "GA"
"Cheyenne", "WY"
3 rows fetched from 2 columns.
To disconnect from a data source
-
For the connection window used in the previous procedure, select Full Disconnect from the Conn menu. ODBC Test disconnects from the data source and removes the connection window.