簡體   English   中英

可以偷看DataTable行中的下一個值嗎?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM