比较数据表与不同表中的同一列vb.net

时间:2019-05-20 07:19:38

标签: vb.net datatable

我想创建评估程序来比较两个表(输入和验证),无论它们是否具有相同的数据。第二列的表数相同。例如,有T_A_Entry,T_A_Val,T_B_Entry,T_B_Val,T_C_Entry,T_C_Val等。

我已经用组合框填充了数据库中的所有表。 combobox1选择条目表,combobox2选择验证表,combobox3选择列(但这是可选的)。我不知道如何在每列中进行比较。

See image of the tables

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    svr = TextBox1.Text

    ComboBox1.Items.Clear()

    If Button1.Text = " Connected " Then
        Button1.Text = "Connect"
        cn.Close()

        Exit Sub
    End If

    Call conDB()
    Try
        cn.Open()
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try

    If cn.State = ConnectionState.Open Then
        Button1.Text = "Connected"

        comm.CommandText = "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE' ORDER BY 'TABLE_NAME' ASC"
        dr = comm.ExecuteReader
        If dr.HasRows Then
            ComboBox1.Items.Clear()
            ComboBox2.Items.Clear()
            While dr.Read()
                ComboBox1.Items.Add(dr("TABLE_NAME"))
                ComboBox2.Items.Add(dr("TABLE_NAME"))
            End While
        End If
        dr.Close()
        cn.Close()

    Else
        MessageBox.Show("Fail to Connect")
        Button1.Text = "Connect"
    End If
End Sub

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
    Dim xsql As String
    ' mencari nama kolom tabel
    xsql = " SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME= '" & ComboBox1.Text & "'"

    Call conDB()
    cn.Open()
    comm.CommandText = xsql
    dr = comm.ExecuteReader

    If dr.HasRows Then
        ComboBox3.Items.Clear()
        While dr.Read()
            ComboBox3.Items.Add(dr.Item(0))
        End While
    End If
    dr.Close()
    cn.Close()
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    Me.Close()
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Call FillGrid(ComboBox1.Text, ComboBox2.Text, ComboBox3.Text)
End Sub

Private Sub FillGrid(ByVal tabelEntry As String, ByVal tabelValidasi As String, ByVal variabel As String)
    Dim ds As New DataSet()

    'helpp....

End Sub

0 个答案:

没有答案