|
-
May 7th, 2013, 01:01 PM
#1
Thread Starter
Member
[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?
-
May 7th, 2013, 01:04 PM
#2
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 7th, 2013, 01:23 PM
#3
Thread Starter
Member
Re: [VB.NET] Fill combobox from MySQL!
Thanks. How do I fill a datatable though?
-
May 7th, 2013, 01:24 PM
#4
Re: [VB.NET] Fill combobox from MySQL!
what do you have so far?
post your code + i'll show you how to modify it
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 7th, 2013, 01:45 PM
#5
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")
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 8th, 2013, 08:51 AM
#6
Thread Starter
Member
Re: [VB.NET] Fill combobox from MySQL!
 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?
Last edited by aristide; May 8th, 2013 at 09:03 AM.
-
May 8th, 2013, 09:19 AM
#7
Re: [VB.NET] Fill combobox from MySQL!
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|