简体   繁体   English

如何比较DataTable中row的值?

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

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

2.) 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). 我存储的数据包含所有数据到数据集(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). 我想输入dtClone(名称列和计数列),具有序列且没有重复的数据(名称列)并填充计数列(名称列中包含相同位数)。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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