SQL 存储过程和数据集
我有一个在 SSMS 中运行良好的 sql 存储过程。当我尝试通过代码执行并将返回值分配给数据集时,我得到的行数为零。我已经使用立即窗口来确保将正确的参数发送到存储过程,这一切都很好。
还有什么会导致我将零行分配给数据集。这是我的代码。
谢谢, Mike
编辑:我没有从 SQL 中得到任何异常..
公共函数 GetTransReporting(ByVal transNumber As Long, ByVal customerID As Long) As DataCommon.transReporting
Dim myTransReporting As New transReporting
Dim da As SqlDataAdapter
Dim prm1 As SqlParameter
Dim prm2 As SqlParameter
mcmd = New SqlCommand
mcmd.CommandType = CommandType.StoredProcedure
mcmd.Connection = mcn
mcmd.CommandText = "GetTransReportingByCustomerID"
prm1 = New SqlParameter("@transNumber", Data.SqlDbType.BigInt)
prm1.Value = customerID
mcmd.Parameters.Add(prm1)
prm2 = New SqlParameter("@customerNumber", Data.SqlDbType.BigInt)
prm2.Value = transNumber
mcmd.Parameters.Add(prm2)
da = New SqlDataAdapter(mcmd)
da.Fill(myTransReporting)
Return myTransReporting
结束函数
I've got a sql stored proc that is working fine in SSMS. When I try and execute through code and assign the return to a dataset I am getting zero rows back. I've used the immediate window to ensure that I am sending the correct params to the stored proc and that is all good.
What else would cause me to get zero rows assigned to the dataset. Here is my code.
Thanks,
Mike
EDIT: I'm not getting any exceptions from SQL..
Public Function GetTransReporting(ByVal transNumber As Long, ByVal customerID As Long) As DataCommon.transReporting
Dim myTransReporting As New transReporting
Dim da As SqlDataAdapter
Dim prm1 As SqlParameter
Dim prm2 As SqlParameter
mcmd = New SqlCommand
mcmd.CommandType = CommandType.StoredProcedure
mcmd.Connection = mcn
mcmd.CommandText = "GetTransReportingByCustomerID"
prm1 = New SqlParameter("@transNumber", Data.SqlDbType.BigInt)
prm1.Value = customerID
mcmd.Parameters.Add(prm1)
prm2 = New SqlParameter("@customerNumber", Data.SqlDbType.BigInt)
prm2.Value = transNumber
mcmd.Parameters.Add(prm2)
da = New SqlDataAdapter(mcmd)
da.Fill(myTransReporting)
Return myTransReporting
End Function
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
明白了..如果你看看我上面的参数,我不小心将交易分配给客户,并将客户分配给交易。卫生部!
谢谢,
麦克风
Got it.. if you take a look at my parameters up top I am accidentally assigning transaction to customer and customer to transaction. DOH!
Thanks,
Mike
您的存储过程是否以 SET NOCOUNT ON 开头?如果存储过程在最终 SELECT 之前处理多个查询,则缺少此功能有时会导致问题。
Does your stored procedure start with SET NOCOUNT ON? The lack of this can sometimes cause issues if the stored procedure is processing multiple queries before the final SELECT.