Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

recordset problem

0 views
Skip to first unread message

Chuck Smith

unread,
Nov 9, 2008, 10:09:18 PM11/9/08
to
Can't figure this one out. Last line of code fails. I can write the field
names into the excel worksheet but vb2008.net fails on the last line
.copyfromrecordset....

Any ideas?


' login to the test db and select all records, then place headers +
data into Excel...
Dim MySQLConn
Dim sqlstr As String
Dim MySQLRS
MySQLConn = CreateObject("ADODB.Connection")
MySQLConn.open = "DRIVER={MySQL ODBC 5.1
Driver};SERVER=serveraddress;DATABASE=mydata;UID=dbuser;PWD=password;OPTION=35;"
sqlstr = "SELECT Tbl.ID_no FROM Tbl WHERE Tbl.ID_no='N79938';"
MySQLRS = CreateObject("ADODB.Recordset")
MySQLRS.open(sqlstr, MySQLConn, 1, 4, 1)

Dim Excel
Excel = CreateObject("Excel.Application")
Excel.visible = True
Excel.Workbooks.Add()
Dim i
' .Cells(column, row) convention, by ADO recordset uses 0-based
versus excel's
' 1-based subscripts...
For i = 0 To MySQLRS.fields.count - 1
Excel.Workbooks(1).Worksheets(1).Cells(1, i + 1).value =
MySQLRS.fields(i).name
Next

'Excel.Workbooks(1).Worksheets(1).Range("A2").CopyFromRecordset(MySQLRS)

0 new messages