哪位高手帮我看一下, 错误是初始化不符合OLE DB 规定
PublicFunctionExeSQL(ByValsqlAsString)AsADODB.RecordsetDimcnAsADODB.ConnectionDimrsAs...
Public Function ExeSQL(ByVal sql As String) As ADODB.Recordset
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strConnection As String
Dim strArray() As String
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
On Error GoTo ErrHandler:
strConnection = "Provider =SQLOLEDB.1;" & " Integrated Security=SSPI;" & " Persist Security Info = Fasle; " & "Initial Catalog=pos;" & "Data Source=CHINA-449C55240"
strArray = Split(sql)
cn.Open strConnection
If StrComp(UCase$(strArray(0)), "select", vbTextCompare) = 0 Then
rs.Open Trim$(sql), cn, adOpenKeyset, adLockOptimistic
Set ExeSQL = rs
Else
cn.Execute sql
End If
ExeSQL_Exit:
Set rs = Nothing
Set cn = Nothing
Exit Function
ErrHandler:
'显示错误信息
MsgBox "错误号:" & Err.Number & " 错误信息:" & Err.Description, vbExclamation
Resume ExeSQL_Exit
End Function 展开
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strConnection As String
Dim strArray() As String
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
On Error GoTo ErrHandler:
strConnection = "Provider =SQLOLEDB.1;" & " Integrated Security=SSPI;" & " Persist Security Info = Fasle; " & "Initial Catalog=pos;" & "Data Source=CHINA-449C55240"
strArray = Split(sql)
cn.Open strConnection
If StrComp(UCase$(strArray(0)), "select", vbTextCompare) = 0 Then
rs.Open Trim$(sql), cn, adOpenKeyset, adLockOptimistic
Set ExeSQL = rs
Else
cn.Execute sql
End If
ExeSQL_Exit:
Set rs = Nothing
Set cn = Nothing
Exit Function
ErrHandler:
'显示错误信息
MsgBox "错误号:" & Err.Number & " 错误信息:" & Err.Description, vbExclamation
Resume ExeSQL_Exit
End Function 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询