Hi... I'm trying to add a name of a product to a Textbox...the name of the product is stored in a database. Now there is a Combobox with number in them....1 2 3 ect. Now if you select one of the numbers it must display that product name? I know its probably why off but it would be great if you could help :)

conn.Open
Textbox1.Clear()
myDataSet.Clear

mycommand.Commandtext = "Select Prodcut Name FROM Products WHERE ProductID = '" & ComboBox1.SelectedItem & "'  "

mydataAdapter.selectcommand = mycommand
mydataAdapter.selectcommand.Connection = conn
Textbox1.Text = convert.ToString(mydataAdaptor)
conn.close

Learn ADO.NET Data Provider classes.

mycommand.Commandtext = "Select [Prodcut Name] FROM Products WHERE ProductID = @pid"
mycommand.Connection=conn
mycommand.Parameters.AdddWithValue("@pid",ComboBox1.SelectedValue)

conn.Open()
Dim obj as Object=mycommand.ExecuteScalar()
If IsNothing(obj) Then
  Textbox1.Text = "Not Found"
ELSE
  TextBox1.Text=obj.ToString()
End IF
conn.Close()

Thanks so much its working great but now it only adds the right one the first time then the second time it keeps adding the same entry... I know I got to clear something but not to sure what lol

Thanks so much its working great but now it only adds the right one the first time then the second time it keeps adding the same entry... I know I got to clear something but not to sure what lol

the text box?

the text box?

Yeah in the taxtbox....I tried clearing the textbox every time it runs but it just keeps adding the same entry to it, doesnt change the entry of it.

Private Sub ComboBox1SelectedIndexChanged(sender As System.Object, e As System.EventArgs)
     	 	Textbox1.Clear
     	 	Conn = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;data source=C:\temp\CBDdb1.mdb")
     	 	mycommand.Commandtext = "SELECT [Product Name] FROM Products WHERE ProductID = @pid"
     		mycommand.Connection=conn
     	 	mycommand.Parameters.Add("@pid",ComboBox1.Selecteditem)
       
     	 	conn.Open()
    	 	  Dim obj as Object=mycommand.ExecuteScalar()
    	 	  If obj is nothing Then
    	   		  Textbox1.Text = "Not Found"
     	 	  ELSE
     	   		  TextBox1.Text=obj.ToString()
     	 	  End If
     	 	conn.Close()
			     
  End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.