Using ODBCLink/SE With ODBC Applications

ODBCLink/SE Reference Manual

Using Visual Basic (4.0 or higher)

You can use ODBCLink/SE either with VB Database controls or with Database and dynaset variables. In addition, of course, you may call ODBC functions directly from the DLL.

To use VB database controls, define a data control and assign it a Connect property of the form "DSN=HP3000;UID=users;PWD=password" and a RecordSource property of the form "SELECT * FROM TableName". If you want to create a SnapShot (no update) set the Options property to 64 (SQL_PASSTHROUGH). You may then place text controls on the screen, set the DataSource property to the name of the data control, and set the DataField property to the name of the column in the Select statement. When the application is run, it will download all records qualified by the Select statement (or all primary key values, depending on the SQL_PASSTHROUGH option) and display the first record on the screen. You may scroll through the records by using the "Up", "Down", "Top", "Bottom" buttons on the data control.

A second option is to use dynaset variables which gives the program more control, such as for loading a grid with data. Define a database object, assign it Connect and Options properties as above, and open it with an OpenDatabase call, as in SET DBVar=OpenDatabase(...). Then define a dynaset variable (DIM DSVar as DYNASET) and open it with a statement of the form "Set DSVar=DBVar.OpenDynaset (SQLstatement)." If SQL Statement is a Select statement, you can read the results from "DSVar.FieldName" and move to the next record with "DSVar.MoveNext". If SQLStatement is an Insert or Update statement, no results are returned. You can update records with the Update method, and you can get the selection count by calling SQLRowCount or with a query of the form "Select COUNT(*) From Table Where Conditions". To update the table, you will of course need a primary key defined and you will need to disable the SnapShot only button.

A third option is to call ODBC functions directly. Generally you will do an SQLAllocEnv, SQLAllocConnect and SQLDriverConnect to open the database, followed by SQLExecDirect, followed by multiple SQLFetch and SQLGetData calls. If you plan to use SQLBindCol to bind fetch results to local variables you must use the following procedure:

A)Declare strings variables as: Dim mystr as String

B)Initialize your string variables before use: mystr=String(255,0)

C)Use the ByVal keyword when passing the variable to the ODBC driver. Do not use the ByVal keyword in the AlpbBuf@ parameter except for character data, as the goal is to pass the address of the parameter, not the value. Declare SQLBindCol as follows:

Declare Function SQLFindCol Lib Aodbc.dll@ (ByVal hstmt AS long, ByVal col As Integer, By Val wConvType As Integer, lpdBuf As Any, ByVal dwbuflen As Long, lpcbout As Long) As Integer.

 

ODBCLink/SE

48

©M.B. Foster Associates Limited 1995-2000

Page 58
Image 58
HP MPE/iX 6.x Operating System manual Using Visual Basic 4.0 or higher