sql – 运行存储过程并从VBA返回值
发布时间:2021-01-16 21:42:49 所属栏目:编程 来源:网络整理
导读:我想将参数传递到SQL Server 2008中的存储过程,我想将结果存储在ADODB.Recordset中 目前我有这个: Public Sub UpdateWithStoredProcedure() Dim cmd As New ADODB.Command Dim conn As ADODB.Connection Dim prm As ADODB.Parameter Dim strConn As String D
我想将参数传递到SQL Server 2008中的存储过程,我想将结果存储在ADODB.Recordset中 目前我有这个: Public Sub UpdateWithStoredProcedure() Dim cmd As New ADODB.Command Dim conn As ADODB.Connection Dim prm As ADODB.Parameter Dim strConn As String Dim strSQL As String strConn = "Provider=SQLOLEDB.1;" & _ "Data Source=(local); Initial Catalog=NorthWind;" & _ "Integrated Security=SSPI" Set conn = New ADODB.Connection conn.Open strConn Set cmd = New ADODB.Command cmd.CommandText = "procOrderUpdate" cmd.CommandType = adCmdStoredProc cmd.ActiveConnection = conn Set prm = cmd.CreateParameter("OrderID",adInteger,adParamInput) cmd.Parameters.Append prm cmd.Parameters("OrderID").Value = 1 Set prm = cmd.CreateParameter("OrderDate",adDate,adParamInput) cmd.Parameters.Append prm cmd.Parameters("OrderDate").Value = "1/1/2007" Set prm = cmd.CreateParameter("ShipVia",adParamInput) cmd.Parameters.Append prm cmd.Parameters("ShipVia").Value = 2 Set prm = cmd.CreateParameter("Freight",adCurrency,adParamInput) cmd.Parameters.Append prm cmd.Parameters("Freight").Value = "10.5" 'Execute the Stored Procedure cmd.Execute 'Close the connection conn.Close End Sub 问题是如何将其存储在记录集中而不是仅执行它? 解决方法我相信你所需要的就是这个Dim Rst As ADODB.Recordset 和这个 Set Rst = cmd.Execute (编辑:广西网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
站长推荐