【问题标题】:ExecuteXmlReader and null Resultset Throws TargetInvocationExceptionExecuteXmlReader 和 null 结果集引发 TargetInvocationException
【发布时间】:2009-03-02 15:49:40
【问题描述】:

我在返回 XML 结果集的 SQL Server 2005 数据库上调用存储过程。有时它会返回一个空结果集,因为没有要返回的行。发生这种情况时,ExecuteXmlReader 方法会引发 TargetInvocationException。这似乎是一个已知问题(请参阅:http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/5e90e3c0-605b-406d-848a-dea7b16f458e/)。
处理此异常的最佳方法是什么?

【问题讨论】:

    标签: xml sql-server-2005 exception null resultset


    【解决方案1】:

    我能想到 3 个选择

    1. 修改存储过程以返回一个虚拟/空值
    2. 修改代码 - 捕获异常并且什么都不做 - 或记录错误
    3. 使用 DataSet - 您应该得到一个空的 DataSet,所以只需检查 DataSet 是否为空。

    作为第三选择的相关 SO 帖子,这里有一个关于如何检查 DataSet 是否为空的 SO 问题

    In C#, what is the best way to test if a dataset is empty?

    【讨论】:

      猜你喜欢
      • 2017-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-09
      相关资源
      最近更新 更多