简体   繁体   English

可以偷看DataTable行中的下一个值吗?

[英]Is it possible to peek at the next value in a DataTable Row?

I have a DataTable that contains 4 rows. 我有一个包含4行的数据表。 I want to compare a value in one column in row 1 with the value in row 2. Something similar to this: 我想将第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

You keep track of the last item: 您跟踪最后一个项目:

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

You can always access a DataRow with its index ( DataRowCollection.Item ): 您始终可以使用其索引( 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

Say you have the following table: 假设您有下表:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM