使用SQL Server 2012 \ Excel 2010. Excel調用將返回1或2的SQL SP,然後我需要基於此執行其他操作。Excel中的VBA查詢記錄集值SQL類型不匹配錯誤
Dim con As ADODB.Connection
Dim cmd As ADODB.Command
Dim rs As ADODB.RecordSet
Dim WSP1 As Worksheet
Set con = New ADODB.Connection
Set cmd = New ADODB.Command
Set rs = New ADODB.RecordSet
' Log into our SQL Server, and run the Stored Procedure
con.Open "Provider=SQLOLEDB;Data Source=xxxxxxxx;Initial Catalog=xxxxxxx;Integrated Security=SSPI;Trusted_Connection=Yes;"
cmd.ActiveConnection = con
' Set up the parameter for our Stored Procedure
' (Parameter types can be adVarChar,adDate,adInteger)
cmd.Parameters.Append cmd.CreateParameter("User", adVarChar, adParamInput, 15, Trim(Range("C7").Text))
Application.StatusBar = "Running stored procedure..."
cmd.CommandText = "usp_GL_Code_Access"
Set rs = cmd.Execute(, , adCmdStoredProc)
If rs = 1 Then
MsgBox "true"
Else
MsgBox "false"
rs.Close
Set rs = Nothing
Set cmd = Nothing
con.Close
Set con = Nothing
目前我只是使用MSGBOX真\假看到從RS \ SQL SP的價值,但我不斷收到錯誤消息「類型不匹配」,它凸顯了
IF rs = 1 Then
線。
任何想法?
將Excel中真正看到1或2,但?我需要繼續SP,並說如果1然後做這個別的做別的 – Michael