SQL 存储过程和数据集

发布于 2024-08-11 04:42:12 字数 1017 浏览 12 评论 0原文

我有一个在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟花易冷人易散 2024-08-18 04:42:12

明白了..如果你看看我上面的参数,我不小心将交易分配给客户,并将客户分配给交易。卫生部!

谢谢,
麦克风

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

指尖凝香 2024-08-18 04:42:12

您的存储过程是否以 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文