错误从gridview返回空arraylist

时间:2014-11-26 17:10:35

标签: asp.net vb.net gridview

我尝试比较两个arraylist并检查两者之间的差异。我从Gridview1手动创建的第一个arraylist,以及从数据库中检索一些数据的第二个arraylist。

到目前为止,这是我的代码:

    Protected Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
    Dim strCheck As String = txtQuery.Text
    Dim arrayList1 As ArrayList = New ArrayList()
    Dim arrayList2 As ArrayList = New ArrayList()
    Dim arrayList3 As ArrayList = New ArrayList()

    Dim a As Integer
    Dim b As Integer
    Dim c As Integer
    Dim d As Integer
    If strCheck.IndexOf("SELECT", StringComparison.CurrentCultureIgnoreCase) >= 0 And
        strCheck.IndexOf("Customer ID", StringComparison.CurrentCultureIgnoreCase) >= 0 And
        strCheck.IndexOf("SUM", StringComparison.CurrentCultureIgnoreCase) >= 0 And
        strCheck.IndexOf("Price ($)", StringComparison.CurrentCultureIgnoreCase) >= 0 And
        strCheck.IndexOf("Total Prices", StringComparison.CurrentCultureIgnoreCase) >= 0 And
        strCheck.IndexOf("tbl_product", StringComparison.CurrentCultureIgnoreCase) >= 0 And
        strCheck.IndexOf("GROUP BY", StringComparison.CurrentCultureIgnoreCase) >= 0 Then
        For a = 0 To Gridview2.Rows.Count - 1 Step 1
            For b = 0 To Gridview2.Columns.Count - 1 Step 1
                arrayList1.Add(Gridview2.Rows(a).Cells(b).Text)
                'TarrayList1.Add(arrayList1.Sort())
                arrayList1.Sort()
            Next
        Next

        For c = 0 To GridView3.Rows.Count - 1 Step 1
            For d = 0 To GridView3.Columns.Count - 1 Step 1
                arrayList2.Add(GridView3.Rows(c).Cells(d).Text)
                arrayList2.Sort()
            Next
        Next

        For Each listElement As String In arrayList1
            If Not arrayList2.Contains(listElement) Then
                arrayList3.Add(listElement)
            End If
        Next

        For Each listElement As String In arrayList2
            If Not arrayList1.Contains(listElement) Then
                arrayList3.Add(listElement)
            End If
        Next

        Dim dtNew As DataTable = New DataTable()
        dtNew.Columns.Add("Array")
        Dim j As Integer
        For j = 0 To arrayList3.Count - 1 Step 1
            dtNew.Rows.Add()
            dtNew.Rows(j)("Array") = arrayList3(j).ToString()
        Next
        GridView4.DataSource = dtNew
        GridView4.DataBind()

        If GridView4.Rows.Count = 0 Then
            MsgBox("TRUE")
        Else
            MsgBox("FALSE")
        End If
    Else
        MsgBox("False")
    End If
End Sub

> 代码将比较arraylist1和arraylist2,如果有任何差异,那么它将被添加到arraylist3。

错误结果是 arrayList2 我不知道为什么当我检查arraylist2时它返回一个空的arraylist。

你有什么建议为什么代码会出现这样的错误?

提前致谢。

0 个答案:

没有答案