Hi
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.
when i run the code it , i dont get any error but it does not load the tables in comboboxes . can someone please examine the code
Thanks in advance
Imports System.Data.OleDb
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private conn As OleDbConnection
Private sda As OleDbDataAdapter
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\dtb.accdb;Jet OLEDB:Database Password=****")
sda = New OleDbDataAdapter([String].Empty, conn)
conn.Open()
ComboBox2.DataSource = conn.GetSchema("TABLES")
ComboBox2.ValueMember = "TABLE_NAME"
ComboBox2.DisplayMember = "TABLE_NAME"
ComboBox1.DataSource = conn.GetSchema("TABLES")
ComboBox1.ValueMember = "TABLE_NAME"
ComboBox1.DisplayMember = "TABLE_NAME"
End Sub
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
If ComboBox1.SelectedItem IsNot Nothing AndAlso ComboBox2.SelectedItem IsNot Nothing AndAlso TextBox1.Text IsNot Nothing Then
Dim cmd As OleDbCommand = conn.CreateCommand()
cmd.CommandText = ("insert into " + ComboBox1.Text & "(studName) values('") + TextBox1.Text & "')"
sda.InsertCommand = cmd
sda.InsertCommand.ExecuteNonQuery()
cmd.CommandText = ("insert into " + ComboBox2.Text & "(studName) values('") + TextBox1.Text & "')"
sda.InsertCommand = cmd
sda.InsertCommand.ExecuteNonQuery()
sda.Dispose()
conn.Close()
conn.Dispose()
End If
End Sub
End Class