使用VBA中的两个参数调用SQL Server过程
我在Excel中实现了一些VBA代码,它调用一个SQL Server存储过程,该存储过程需要两个参数:integer和date 问题:如果在Excel中执行VBA代码,则从SQL Server过程中得不到任何数据 我也没有收到任何错误消息 如果我在SQL Server Management Studio中使用使用VBA中的两个参数调用SQL Server过程,sql,sql-server,vba,excel,stored-procedures,Sql,Sql Server,Vba,Excel,Stored Procedures,我在Excel中实现了一些VBA代码,它调用一个SQL Server存储过程,该存储过程需要两个参数:integer和date 问题:如果在Excel中执行VBA代码,则从SQL Server过程中得不到任何数据 我也没有收到任何错误消息 如果我在SQL Server Management Studio中使用 EXEC [dbo.spsClient] '123456' '01.01.2014' 我从SQL Server过程中获取了一些数据。我想我在处理VBA中的两个参数时遇到了问题 我实现了以
EXEC [dbo.spsClient] '123456' '01.01.2014'
我从SQL Server过程中获取了一些数据。我想我在处理VBA中的两个参数时遇到了问题
我实现了以下代码:
...
nr = 123456
datepoint = DateValue(ActiveWorkbook.Sheets(sheetData).Cells(4, 3))
Dim ADODBCmd As New ADODB.Command
With ADODBCmd
.ActiveConnection = objconn
.CommandTimeout = 500
.CommandText = "dbo.spsClient"
.CommandType = adCmdStoredProc
.Parameters.Refresh
.Parameters.Append ADODBCmd.CreateParameter("@number", adVarChar, adParamInput, 50, nr)
.Parameters.Append ADODBCmd.CreateParameter("@date", adDate, adParamInput, datepoint)
Set recordset = .Execute()
End With
我解决了我的问题:在第二个Append.Parameters中,我忘记验证大小,在本例中是50
感谢您的帮助。尝试以字符串形式发送硬编码日期,以消除格式问题。在SQL Profiler运行的情况下检查查询,查看实际发送到数据库的内容。我还尝试了硬编码日期和nr。它仍然不起作用…:从探查器中捕获,将SQL复制到ManagementStudio中,然后查看内容up@AlexK.,我在SQL Management studio中进行了尝试,并得到了结果,对此我深表歉意。@vc74:您能更准确地说吗?