[英]Is it possible to peek at the next value in a DataTable Row?
我有一个包含4行的数据表。 我想将第1行中的一列中的值与第2行中的值进行比较。类似于以下内容:
For Each row As DataRow in drRows
If row("column") <> row("column") 'I want the second row("column") to be the next row.
'do something else
End If
Next
您跟踪最后一个项目:
Dim last As DataRow = Nothing
For Each row As DataRow In drRows
If last IsNot Nothing Then
' Compare last with row
End If
last = row
Next
您始终可以使用其索引( DataRowCollection.Item
)访问DataRow
:
For i As Integer = 0 To tbl.Rows.Count - 1
Dim row As DataRow = tbl.Rows(i)
If i <> tbl.Rows.Count - 1 Then
Dim nextRow As DataRow = tbl(i + 1)
If row("column").Equals(nextRow("column")) Then
'do something"
End If
End If
Next
假设您有下表:
A B C D
1 2 3 4
5 6 7 8
9 10 11 12
12 12 13 14
For i As Integer = 0 To dt.Rows.Count - 2
If dt.Rows(i)("ColName") <> dt.Rows(i + 1)("ColName") Then
'Do something
End If
Next
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.