VB.NET datarow不会执行比较

时间:2015-08-02 14:49:25

标签: vb.net dataset comparison datarow

我有一个包含2列的表

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

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

这是我的代码:

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

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

1 个答案:

答案 0 :(得分:0)

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

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

preVal = -1
preVal = myDataRow.Item("Col1").ToString().Trim()
相关问题