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?
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: