这个代码是用指定单元格里的数据做为条件查询SQL server数据到指定的行列。但是出错了,各位帮我看一下!
Private Sub abc()
Dim oConn1 As New ADODB.Connection
Dim oRS1 As New ADODB.Recordset
Dim SQL As String
Dim InOut, IsParts As String
Dim i As Integer
currentrow = 10
i = 0
oConn1.Open "DSN=sjj;uid=sa;pwd=123456;database=jackydata"
If Cells(currentrow, 1).Value <> "" Then
Range(Cells(currentrow, 1), Cells(currentrow, 2)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
End If
SQL = "Execute CheckStockReturnMatStatusForVod '" & Cells(6, 5).Value & "'"
Set oRS1 = New ADODB.Recordset
oRS1.Open SQL, oConn1
If oRS1.EOF Then
MsgBox ("查询完成")
Exit Sub
End If
i = 1
Sheet1.Cells(5, 3).Value = oRS1.Fields("NoOfRec")
currentrow = 10
Sheet1.Cells(currentrow, 1).Select
Do While Not oRS1.EOF
Sheet1.Cells(currentrow, 1).Value = oRS1.Fields("name")
Sheet1.Cells(currentrow, 2).Value = oRS1.Fields("phone")
currentrow = currentrow + 1
oRS1.MoveNext
Cells(currentrow, 1).Select
Loop
If oRS1.State = adStateOpen Then
oRS1.Close
End If
Set oRS1 = Nothing
If oConn1.State = adStateOpen Then
oConn1.Close
End If
currentrow = 6
Cells(currentrow, 1).Select
End Sub
到这里就出错了,
Set oRS1 = New ADODB.Recordset
oRS1.Open SQL, oConn1
If oRS1.EOF Then
MsgBox ("查询完成")
Exit Sub
End If
i = 1
Sheet1.Cells(5, 3).Value = oRS1.Fields("NoOfRec")
说 运行时错误'-2147217900 (80040e14)';
自动化(Automation)错误
各位大虾帮我看一下修改一下,多谢了!