rs.RecordCount返回值-1问题,大虾请赐教,在线等待!!!
代码如下:
Private Sub Command1_Click()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.ConnectionString = "DRIVER={MySQL ODBC 5.1 Driver}; SERVER=10.80.72.216; DATABASE=yaf;UID=root;PWD=root; OPTION=3"
cn.Open
cbo1size = Combo1.Text
cbo6displaytype = Combo6.Text
ttTest_Item = Text8.Text
ttTest_contents = Text9.Text
sql1 = "select * from projectTest5192 where Size = '" & cbo1size & "' and displayType = '" & cbo6displaytype & " '"
rs.Open sql1, cn, 3, 3
MsgBox "rs.RecordCount3=" & rs.RecordCount
Dim oWorkBook As Workbook
Set oExcel = New Excel.Application
Dim oWorkSheet As Worksheet
Set oWorkBook = oExcel.Workbooks.Open("G:\zhangyongxing\VB\518\123.xlsx")
Set oWorkSheet = oWorkBook.Worksheets(1)
oExcel.Visible = True '设置EXCEL对象可见(或不可见)
For i = 0 To rs.RecordCount
oWorkSheet.Cells(1, i + 1) = rs.Fields(i).Name
oWorkSheet.Cells(2, i + 1) = rs.Fields(i).Value
Next
End Sub
数据库是MySQL,里边好几条记录啊,为啥读不了啊??
要是能给点如何显示记录集的建议就更好啦,大学时学过VB现在想给科室做个小数据查询软件,发现以前学的太次啦,见笑啦。
[解决办法]
没看出什么问题.难道和mysql的驱动有关?不了解连接字符串中的option=3的含义,不知道是不是和这个有关.试试在cn.open前加上cn.cursorlocation=3?
[解决办法]