I was hoping someone could offer me some help please
I have a form with two comboboxes ,one text box and a button .I have multiple tables in ms access database with same structure , col1 and col2 .
I want to insert text box value into column1 in the table selected from combobox1 and into column2 in table selected from combobox2
such as if i select table1 from combobox1 and table2 from combobox2 and click on the button, data should be inserted into both table1 and table2.
I can load tables into combobox but i dont know how to handle the issue.can someone tell me (if it is possible) how can i do it
Code:
Private con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\testdb.accdb;Persist Security Info=False")
Private adapter As New OleDbDataAdapter(String.Empty, Me.con)
Private data As DataTable
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As EventArgs) Handles MyBase.Load
con.Open()
Me.ComboBox1.DisplayMember = "TABLE_NAME"
Me.ComboBox1.ValueMember = "TABLE_NAME"
Me.ComboBox1.DataSource = Me.con.GetSchema("TABLES")
Me.ComboBox2.DisplayMember = "TABLE_NAME"
Me.ComboBox2.ValueMember = "TABLE_NAME"
Me.ComboBox2.DataSource = Me.con.GetSchema("TABLES")
con.Close()
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, _
ByVal e As EventArgs) Handles ComboBox1.SelectedIndexChanged
If Me.ComboBox1.SelectedItem IsNot Nothing Then
Me.data = New DataTable
Me.adapter.SelectCommand.CommandText = String.Format("SELECT * FROM [{0}]", Me.ComboBox1.SelectedValue)
End If
End Sub
Private Sub Button1_Click(ByVal sender As Object, _
ByVal e As EventArgs) Handles Button1.Click
If Me.data IsNot Nothing Then
Dim builder As New OleDbCommandBuilder(Me.adapter)
Me.adapter.Update(Me.data)
End If
End Sub