Article ID: 129570
Article Last Modified on 10/11/2006
-or-
Sub GetData()
Dim Chan as Integer
' Establish a connection with the Oracle Data Source.
Chan = SQLOpen("DSN=oracledata;UID=userid;PWD=password")
' Execute a query which is expected to return two columns of data.
SQLExecQuery Chan, _
"SELECT EMPS.LAST_NAME, EMPS.FIRST_NAME FROM NORTHWIND.EMPS EMPS"
SQLRetrieve Chan, ActiveSheet.Range("A1")
' Execute a second query which is expected to return only one column
' of data.
SQLExecquery Chan, _
"SELECT EMPS.EMPLOYEE_ID FROM NORTHWIND.EMPS EMPS"
SQLRetrieve Chan, Activesheet.Range("D1")
' Close the connection to the Oracle data source.
SQLClose Chan
End Sub
This macro fails because the second query returns fewer columns than the
first query--the second query retrieves only one column of data (EMPLOY_ID)
and the first query retrieves two columns of data (LAST_NAME, FIRST_NAME).
Sub GetData1()
Dim Chan as Integer
' Establish a connection with the Oracle data source.
Chan = SQLOpen("DSN=oracledata;UID=userid;PWD=password")
' Execute a query which is expected to return only one column of
' data.
SQLExecquery Chan, _
"SELECT EMPS.EMPLOYEE_ID FROM NORTHWIND.EMPS EMPS"
SQLRetrieve Chan, Activesheet.Range("D1")
' Execute a second query which is expected to return two columns of
' data
SQLExecquery Chan, _
"SELECT EMPS.LAST_NAME, EMPS.FIRST_NAME FROM NORTHWIND.EMPS EMPS"
SQLRetrieve Chan, Activesheet.Range("A1")
' Close the connection to the Oracle data source.
SQLClose Chan
End Sub
Sub GetData2()
Dim Chan as Integer
' Establish a connection with the Oracle data source.
Chan = SQLOpen("DSN=oracledata;UID=userid;PWD=password")
' Execute a query which is expected to return two columns of data.
SQLExecquery Chan, _
"SELECT EMPS.LAST_NAME, EMPS.FIRST_NAME FROM NORTHWIND.EMPS EMPS"
SQLRetrieve Chan, Activesheet.Range("A1")
' Close the connection to the Oracle data source.
SQLClose Chan
' Re-establish the connection to the Oracle data source.
Chan = SQLOpen("dsn=oracledata;uid=userid;pwd=password")
' Execute a second query which is expected to return only one column
' of data.
SQLExecquery Chan, _
"SELECT EMPS.EMPLOYEE_ID FROM NORTHWIND.EMPS EMPS"
SQLRetrieve Chan, Activesheet.Range("D1")
' Close the connection to the Oracle data source.
SQLClose Chan
End Sub
Additional query words: 5.00c addin
Keywords: kbbug kbcode kbfix kbprogramming KB129570