MySQL Connector/Net, Populate Combo Box

smokin

Member
Joined
Apr 22, 2006
Messages
12
Programming Experience
Beginner
I am using the mysql connector/net dll to query a mysql database for my vb 2005 app.

i am trying to populate a comobo box with the firstname nad lastname fields of a table for all users loaded in that table. have previously got the code to work for a datagrid but unsure how to populate a combo box wit all the data. eg want combo box to have a drop down that shows "Lastname, Firstname".

Here is the code so far,

Dim conn AsNew MySqlConnection
Dim myCommand AsNew MySqlCommand
Dim myAdapter AsNew MySqlDataAdapter
Dim myData AsNew DataTable
Dim SQL AsString
SQL = "SELECT e.firstname, e.lastname FROM members e WHERE 1"
conn.ConnectionString = "server=domain.com;" _
&
"user id=database;" _
&
"password=paaword;" _
&
"database=ht3_results"
Try
conn.Open()
Try
myCommand.Connection = conn
myCommand.CommandText = SQL
myAdapter.SelectCommand = myCommand
myAdapter.Fill(myData)
'dgvTournaments.DataSource = myData
cboMembers.DataSource = myData
Catch myerror As MySqlException
MsgBox(
"There was an error reading from the database: " & myerror.Message)
EndTry
Catch myerror As MySqlException
MessageBox.Show(
"Error connecting to the database: " & myerror.Message)
Finally
If conn.State <> ConnectionState.Closed Then conn.Close()
EndTry

I think there is more needed other than just cboMembers.DataSoure = myData as it doesn't display the data :(

Any pointers?
 
Last edited:
dotnet4.jpg


Seems to show a System.Data.DataRowView with the above code ive used. Want it to display Lastname, Firstname for each item in the combo box.

Any help greatly apreciated.
 
anyone able to assist?

ive tried looking on the net for a good readup as well about using the .net/connector mysql dll. anyone have a few good sites for me to further my knowledge about it. need a site that has exmaples of applying/filling different form controls with mysql data.

anyway, anyone albe to assist me about my question with the combo box, i'd be greatly apreciated of you.

kind regards.
 
Back
Top