【问题标题】:System.ArgumentException on DataTable.Select(String)DataTable.Select(String) 上的 System.ArgumentException
【发布时间】:2017-11-24 02:50:07
【问题描述】:

休息并重新查看代码后,我发现了错误。请参阅答案。谢谢您的帮助。

剩下的问题:

  • 为什么它没有在大多数数字上给我一个例外? // 我无法看到结果。我只知道其他人没有例外。
  • 为什么 DataSetDesigner 将该整数(数据库)转换为生成的类中的字符串?

我正在使用 Visual Studio 2017 / Oracle DataSet Designer 在我的应用程序中获取代表我的数据库的类。由于 Oracle 不支持 Visual Studio 2017,但我使用 Visual Studio 2015 来生成我的 .xsd 数据集。

使用下面的代码,我收到一条奇怪的异常消息。

For Each numberRow As myOracleDataSet.CustomerTelNumberRow In numberTbl.Select("customerID = " & row.CustomerID)
    // Some more code
Next

System.InvalidArgumentException:
Range 对象中的最小值 (551) 必须小于或等于最大值 (-1)。

分离我发现的In-clause,异常发生在DataTable.Select调用上。

CutomerID 是数据集设计者提供的String-Property,在选择之前检查了DBNULL。如果DataSet.Select"1=1""CustomerID = CustomerID" 一起执行,则代码可以正常工作。我还检查了 CustomerID 的值,发现当给定CustomerID is 250 时发生异常。使用硬编码 250 而不是 row.CustomerID 给了我同样的例外。所以它可能与我表中的数据有关。我能做些什么呢?

我的字符串语法应该是正确的,因为它适用于其他 ID,并且 .Select-Method 不是我自己生成的。

我在 MSDN support.microsoft.com 上发现了几乎相同的异常,但那里说它仅适用于 .NET Framework 3.5-based applications。我的应用程序正在使用 .NET Framework 4.5.2 。

【问题讨论】:

    标签: .net vb.net select datatable invalidargumentexception


    【解决方案1】:

    我终于解决了!
    虽然消息Min (551) must be less than or equal to max (-1) in a Range object. 在某种程度上令人困惑,但 System.InvalidArgumentException 给了我正确的方向。这是小事:

    CutomerID 是数据集设计者提供的字符串属性

    结合numberTbl.Select("customerID = " & row.CustomerID) 是实际的例外。虽然在大多数情况下,这个 String => Integer 比较在某种程度上起作用,但对于 250 却没有。CustomerID 是两个表中的字符串属性。所以我在不强制转换的情况下将 String 与 Int 进行比较。

    以下线修正修复它。

    ̶n̶̶u̶̶m̶̶b̶̶e̶̶r̶̶t̶̶b̶̶l̶̶.̶̶s̶̶e̶̶l̶̶e̶̶c̶̶t̶("̶c̶̶u̶̶s̶̶t̶̶o̶̶m̶̶e̶̶r̶̶i̶̶d̶̶ ̶=̶ ̶"̶ ̶&̶ ̶̶r̶̶o̶̶w̶̶.̶̶c̶̶u̶̶s̶̶t̶̶o̶̶m̶̶e̶̶r̶̶i̶̶d̶)
    numberTbl.Select("customerID = '" & row.CustomerID & "'")
    
    "CustomerID = 250"
    "CustomerID = '250'"
    

    【讨论】:

      【解决方案2】:

      当没有从数据库返回的行时会发生这种情况。

      查询有问题。

      【讨论】:

      • 使用MsgBox(numberTbl.Rows.Count)我发现数据库给了我747 rows。查询似乎没问题。同样使用.Select("customerID = " & 123123123123123),它肯定有0行作为回报,不会给我任何例外。此外 .Select 不与数据库通信,而是与 DataTable 本身 imo。
      猜你喜欢
      • 2019-01-29
      • 1970-01-01
      • 1970-01-01
      • 2017-03-30
      • 2011-03-09
      • 2011-01-20
      • 2014-11-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多