TableAdapter 在 ASP.NET 中返回虚拟结果

发布于 2024-07-26 06:55:32 字数 408 浏览 1 评论 0原文

我有一个 TableAdapter,它从 存储过程 获取行。 由于某种原因,当没有结果时,TableAdapter 将返回值为 0 而不是 NULL 的 INT。 存储过程有 NOCOUNT ON

问题是我在前端有一个 ListView 和一个 EmptyDataTemplate,但没有显示。 当我在查询分析器中运行查询时,我发现它返回 0 而不是 NULL。

该存储过程有一个简单的“SELECT * FROM WHERE”,带有一个 INT 参数(非输出)。 在查询分析器中运行它,我没有得到预期的输出。

这是怎么回事?

I have a TableAdapter that is fetching rows from a stored procedure. For some reason, when there are no results, the TableAdapter returns an INT with value 0 instead of NULL. The stored procedure has NOCOUNT ON.

The problem with this is that I have a ListView in the frontend with an EmptyDataTemplate, which is not being shown. When I ran the query in Query Analyzer, I see that it is returning 0 instead of NULL.

The stored procedure has a simple 'SELECT * FROM WHERE ' with one INT parameter (NOT Output). Running it in Query Analyzer, I get no output, as expected.

What's going on?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

回忆躺在深渊里 2024-08-02 06:55:33

检查查询的 tableAdapter 的 ExcuteMode 属性。 确保将其设置为“阅读器”。 ExecuteMode 有 3 个选项:

  1. Reader - 返回数据行
  2. ​​Scalar - 返回单个值
  3. NonQuery - 返回受影响行数的 int

还要检查参数集合中的返回值参数。 它应该具有属性AllowDBNull(如果允许空值则为true)、Direction(ReturnValue)。 该参数应该保存 SP 的结果。 在您的示例中,它将为空,因为没有返回记录。

Check the ExcuteMode property of the tableAdapter for the query. Be sure it is set to "Reader". There are 3 options for ExecuteMode:

  1. Reader - Returns rows of data
  2. Scalar - Returns single value
  3. NonQuery - Returns an int with number of rows affected

Also check the Parameters Collection for a return value parameter. It should have properites AllowDBNull (true if you allow nulls), Direction (ReturnValue). This parameter should hold the results of your SP. In your example it would be null since there were no records returned.

驱逐舰岛风号 2024-08-02 06:55:33

看起来存储过程正在返回结果。 所有存储过程都返回结果代码。 最有可能的是这个。

It looks like the stored procedure is returning the result. All stored procedures return a result code. It's most likely this.

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