[VB.NET] Fill combobox from MySQL!
Hey guys!
I've got a combobox, and I need to fill it up with data from a column in a MySQL table. When one of the cells is selected, the data in the cell in the next row(on the right) is displayed in a textbox. I know how to create a connection, but I can't figure out how to do the rest. I've searched on internet but without brilliant results. Assuming I the table is like this:
Name|Url
Hello | hello.com
BLA | bla.com
Thanks in advance?
Re: [VB.NET] Fill combobox from MySQL!
use a dataadapter to fill a datatable + set that datatable as your combobox datasource, + the field name as the combobox displaymember
Re: [VB.NET] Fill combobox from MySQL!
Thanks. How do I fill a datatable though?
Re: [VB.NET] Fill combobox from MySQL!
what do you have so far?
post your code + i'll show you how to modify it
Re: [VB.NET] Fill combobox from MySQL!
ok. here's how then:
Code:
Dim con As New MySqlConnection("connection string")
Dim da As New MySqlDataAdapter("SELECT * FROM tableName", con)
Dim dt As New DataTable
da.Fill(dt)
ComboBox1.DisplayMember = "fieldName to show in ComboBox"
ComboBox1.DataSource = dt
TextBox1.DataBindings.Add("Text", dt, "fieldName to show in textbox")
Re: [VB.NET] Fill combobox from MySQL!
Quote:
Originally Posted by
.paul.
ok. here's how then:
Code:
Dim con As New MySqlConnection("connection string")
Dim da As New MySqlDataAdapter("SELECT * FROM tableName", con)
Dim dt As New DataTable
da.Fill(dt)
ComboBox1.DisplayMember = "fieldName to show in ComboBox"
ComboBox1.DataSource = dt
TextBox1.DataBindings.Add("Text", dt, "fieldName to show in textbox")
Thanks! For this code, how would the connection string be?
I got this, Dim con As New MySqlConnection("server=localhost; user id=root; password=; database=test")
Is it ok?
Re: [VB.NET] Fill combobox from MySQL!