DataTable.Select(String)

时间:2017-06-21 09:27:00

标签: .net vb.net select datatable invalidargumentexception

休息一下并重新编写代码后,我发现了错误。见答案。谢谢您的帮助。

留下的问题:

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

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

使用下面的代码我得到一个奇怪的异常消息。

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

System.InvalidArgumentException:
  在Range对象中,Min(551)必须小于或等于max(-1)。

分开我发现的In - 条款,DataTable.Select来电时发生异常。

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

My String语法应该是正确的,因为它适用于其他ID而.select-Method不是由我自己生成的。

我在MSDN support.microsoft.com上发现了几乎相同的例外情况,但它说它仅适用于.NET Framework 3.5-based applications。我的应用程序使用的是.NET Framework 4.5.2。

2 个答案:

答案 0 :(得分:0)

当数据库中没有返回的行时,这会有效。

查询有问题。

答案 1 :(得分:0)

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

  

CutomerID是数据集设计者提供的String-Property

numberTbl.Select("customerID = " & row.CustomerID)结合使用是实际的例外。虽然大多数情况下这个String =>整数比较以某种方式工作,它不适用于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'"
相关问题