合并数据,去重?
Dim dlg As new OpenFileDialog
dlg.MultiSelect = True
dlg.Filter = "数据库|*.mdb"
If dlg.ShowDialog = DialogResult.OK Then
For Each file As String In dlg.FileNames
If Connections.Contains("测试") Then Connections.Delete("测试")
Connections.Add("测试","Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & file & ";Persist Security Info=False")
For Each tn As String In Connections("测试").GetTableNames
If DataTables.Contains(tn) Then
Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.ConnectionName = "测试"
cmd.CommandText = "SELECT * From {" & tn & "}"
dt = cmd.ExecuteReader()
For Each dr As DataRow In dt.DataRows
Dim filter As String = "1=1"
For Each dc As DataCol In dt.DataCols
If DataTables(tn).DataCols.contains(dc.name) Then
If dr.IsNull(dc.name) Then
filter &= " and " & dc.name & " Is null"
ElseIf dc.IsDate Then
filter &= " and " & dc.name & " = #" & dr(dc.name) & "#"
Else
filter &= " and " & dc.name & " = '" & dr(dc.name) & "'"
End If
End If
Next
If DataTables(tn).Find(filter) Is Nothing Then
output.show(filter)
Dim nr As DataRow = DataTables(tn).AddNew()
For Each dc As DataCol In dt.DataCols
If DataTables(tn).DataCols.contains(dc.name) Then
If dr.Isnull(dc.name) Then
nr(dc.name) = Nothing
Else
nr(dc.name) = dr(dc.name)
End If
End If
Next
End If
Next
End If
Next
Next
End If