hStmt Property Example

This example illustrates use of the hStmt property to return a configuration option for a specific statement handle. The example uses the SQLGetStmtOption function to determine the type of cursor created by the OpenResultset method. Note that this value is also supplied by the rdoResultset Type property.

Option Explicit
Dim en As rdoEnvironment
Dim cn As rdoConnection
Dim rs As rdoResultset
Dim rc As Integer
Dim CursorType As Long
Dim T As String

'Declare Function SQLGetStmtOption Lib "odbc32.dll" (ByVal hstmt&, ByVal fOption%, ByRef pvParam As Any) As Integer

Private Sub Form_Load()
Set en = rdoEngine.rdoEnvironments(0)

en.CursorDriver = rdUseOdbc

Set cn = en.OpenConnection(dsName:="WorkDB", _
    prompt:=rdDriverNoPrompt, _
    Connect:="Uid=;pwd=;database=Pubs")
   
Set rs = cn.OpenResultset("Select * from Publishers", _
 rdOpenKeyset, rdConcurRowVer)

Select Case rs.Type
    Case rdOpenForwardOnly: T = "Forward-only"
    Case rdOpenStatic: T = "Static"
    Case rdOpenKeyset: T = "Keyset"
    Case rdOpenDynamic: T = "Dynamic"
End Select
MsgBox "RDO indicates that a " & T  _
   & " Cursor was created"
CursorType = 0
rc = SQLGetStmtOption(rs.hStmt,  _
   SQL_CURSOR_TYPE, CursorType)

Select Case CursorType
    Case SQL_CURSOR_FORWARD_ONLY: T = "Forward-only"
    Case SQL_CURSOR_STATIC: T = "Static"
    Case SQL_CURSOR_KEYSET_DRIVEN: T = "Keyset"
    Case SQL_CURSOR_DYNAMIC: T = "Dynamic"
End Select
MsgBox "ODBC indicates that a " & T  _
   & " Cursor was created"
End Sub