Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert text box value into combobox selected table

Status
Not open for further replies.

rony01

MIS
Sep 12, 2012
8
0
0
US
I am new to vb.net .
I have tables with different names but same columns name.I would like to know how do i insert text box values into combobox selected table ?
any bit of info would be helpful

Code:
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", New String() {Nothing, Nothing, Nothing, "TABLE"})
		con.Close()
	End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\testdb2.accdb")
	  
Dim CmdStr As String = "insert into table1 (a,b,c) values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "')"
		con.Open()
		Dim cmd As OleDbCommand = New OleDbCommand(CmdStr, con)
		cmd.ExecuteNonQuery()
		con.Close()
		MsgBox("Done")
	End Sub
 

Dim CmdStr As String = "insert into [red]" & ComboBox1.SelectedValue & "[/red] (a,b,c) values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "')"

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top