【问题标题】:VB.NET datarow will not perform comparisonVB.NET 数据行将不执行比较
【发布时间】:2015-10-24 17:16:59
【问题描述】:

我有一张有 2 列的表格

+------+------+
| Col1 | Col2 |
+------+------+
| 1000 |    2 |
| 1000 |    4 |
| 1001 |    6 |
| 1002 |    8 |
+------+------+

我正在尝试将当前行的数据行列值与 col1 中的前一个数据行列值进行比较,如果它们相同,则返回当前行的 col2 值

这是我的代码:

if myDataRow.Item("Col1") = preVal Then
id = myDataRow.Item("Col2").ToString()
end if

preVal = -1
preVal = myDataRow.Item("Col1").ToString

【问题讨论】:

    标签: vb.net dataset comparison datarow


    【解决方案1】:

    也许 col1 的末尾有一个额外的空格,所以值不匹配

    if myDataRow.Item("Col1").ToString().Trim() = preVal Then
    id = myDataRow.Item("Col2").ToString()
    end if
    
    preVal = -1
    preVal = myDataRow.Item("Col1").ToString().Trim()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-14
      • 2010-09-19
      • 1970-01-01
      • 2017-07-23
      • 2012-07-02
      • 1970-01-01
      • 2014-12-09
      相关资源
      最近更新 更多