【发布时间】:2016-07-19 17:12:14
【问题描述】:
我目前有两个网格视图,一个来自 SQL 连接,另一个来自 OLEDB2 连接。我可以遍历这些网格视图并检查一个是否包含另一个不包含的值。
我的问题是,当我找到这些值时,我可以将它们放入最终的网格视图中以显示其他两个网格视图之间的共同值吗?
提前感谢您的帮助, 这就是我目前所拥有的。
Puclic Sub CompareDB()
Dim missingRecords As New DataTable
missingRecords = GridView1.DataSource.clone()
GridView3.DataSource = missingRecords
GridView3.DataBind()
Dim V1 As String = ""
Dim V2 As String = ""
Dim msg As String = ""
Dim check As Boolean = False
For Each row As GridViewRow In GridView2.Rows
check = False
For Each rw As GridViewRow In GridView1.Rows
V1 = row.Cells(0).Text
V2 = rw.Cells(0).Text
V2 = Replace(V2, " ", "")
If V1 = V2 Then
check = True
' if check is true
' insert the value V1 and V2 into GridView 3
Exit For
End If
Next
If check = False Then
msg = msg & V1 & " -999 "
End If
Next
msg = msg & "------------------------------------------------------------------ -999 "
For Each row As GridViewRow In GridView1.Rows
check = False
For Each rw As GridViewRow In GridView2.Rows
V1 = row.Cells(0).Text
V2 = rw.Cells(0).Text
V1 = Replace(V1, " ", "")
If V1 = V2 Then
check = True
Exit For
End If
Next
If check = False Then
msg = msg & V1 & " -999 "
End If
Next
' after all checks complete, inserts the the non common values
' into gridview3
' EXAMPLE: GridView3
' gridview1 | gridview2
' v1 | V2
' v1 | V2
' non common|
' | non common
msg = Replace(msg, "-999", "<br />")
' used to output for testing
Label1.Text = msg
End Sub`
【问题讨论】:
-
您可以使用 LINQ 比较这 2 个数据集创建一个新数据集以使用新数据集填充新的 gridview。