简体   繁体   中英

How to compare the value of row in the DataTable?

I want to compare the value of the line name to determine the number of count (the same value) I have tried following two approaches but they didn't match value count:

1.)

dataSet.Rows(i).ItemArray(0).ToString().Equals(dataSet.Rows(j).ItemArray(0).ToString())

2.)

dataSet.Rows(i).ItemArray(0).ToString()= dataSet.Rows(j).ItemArray(0).ToString()

Full code :

Dim count As Integer
count = 0
For i As Integer = 0 To dataSet.Rows.Count - 1
    Dim r As DataRow = dtCloned.NewRow
    r(0) = dataSet.Rows(i).ItemArray(0).ToString()
    For j As Integer = 0 To dataSet.Rows.Count - 1
        If dataSet.Rows(i).ItemArray(0).ToString().Equals(dataSet.Rows(j).ItemArray(0).ToString()) Then
            count = count + 1
        End If
        r(1) = count
    Next
    dtCloned.Rows.Add(r)
Next

I wanted to like this. I store the data contains all the data to the dataset (dataTable). I want to enter into dtClone (name column and count column), data that has sequence and no duplicates (name column) and fill the count column (contain the same number of digits in the name column).

Use this code to easily compare two rows:

    Dim comparer As IEqualityComparer(Of DataRow) = DataRowComparer.Default
    Dim RowEqual = comparer.Equals(ShowRow, OldRow)

    If (RowEqual = True) Then
         NavMessage = "Two rows are equal"
    Else
         NavMessage = "Two rows are not equal"
    End If

用于每个循环比较两个数据表值

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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