query con API ODBC
Publicado por Diego (16 intervenciones) el 12/09/2003 17:13:06
Hola, estoy haciendo una aplicación usando la API ODBC para conectarme y hacer las consultas. De una página de Microsoft obtuve el siguiente código, que funciona bien excepto por el hecho de que al devolver el resultado de las consultas sólo me devuelve valores NULL. Si alguien me pudiera decir qué estoy haciendo mal o enviarme un código que probadamente funcione se lo agradecería mucho.
Dim rc As Integer ' Return code for ODBC functions
Dim henv As Long ' Environment handle
rc = SQLAllocEnv(henv) ' Alloctheenvironmenthandle
Dim hdbc As Long ' Connection handle
rc = SQLAllocConnect(ByVal henv, hdbc) ' Allocate a
' connection handle
Dim DSN As String, UID As String, PWD As String
DSN = "base_datos" ' The data source name
UID = "scott" ' The user's identification
PWD = "tiger" ' The user's password
rc = SQLConnect(hdbc, DSN, Len(DSN), UID, Len(UID), PWD, Len(PWD))
Dim hstmt As Long ' Statement handle
rc = SQLAllocStmt(hdbc, hstmt) ' Allocate a statement ' handle
Dim SQLIn As String
SQLIn = "Select City from Customer"
' Execute the SQL string
rc = SQLExecDirect(hstmt, SQLIn, Len(SQLIn))
If rc = SQL_SUCCESS Or rc = SQL_SUCCESS_WITH_INFO Then
MsgBox "algo hizo"
Else
MsgBox "problema"
End If
Dim field_value As String * 30
Dim LenRead As Long
field_value = String(30, 0)%0
Dim rc As Integer ' Return code for ODBC functions
Dim henv As Long ' Environment handle
rc = SQLAllocEnv(henv) ' Alloctheenvironmenthandle
Dim hdbc As Long ' Connection handle
rc = SQLAllocConnect(ByVal henv, hdbc) ' Allocate a
' connection handle
Dim DSN As String, UID As String, PWD As String
DSN = "base_datos" ' The data source name
UID = "scott" ' The user's identification
PWD = "tiger" ' The user's password
rc = SQLConnect(hdbc, DSN, Len(DSN), UID, Len(UID), PWD, Len(PWD))
Dim hstmt As Long ' Statement handle
rc = SQLAllocStmt(hdbc, hstmt) ' Allocate a statement ' handle
Dim SQLIn As String
SQLIn = "Select City from Customer"
' Execute the SQL string
rc = SQLExecDirect(hstmt, SQLIn, Len(SQLIn))
If rc = SQL_SUCCESS Or rc = SQL_SUCCESS_WITH_INFO Then
MsgBox "algo hizo"
Else
MsgBox "problema"
End If
Dim field_value As String * 30
Dim LenRead As Long
field_value = String(30, 0)%0
Valora esta pregunta


0