Question Locked

Microsoft .Net And MySQL

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
How do i populate Microsoft .Net combobox with information from MySQL database?

2 replies

by tony hopkinson

Assuming you have the Mysqlconnector installed.

Look for Mysql.data.msi on google, if you haven't

connection = new MySqlConnection("server=myserver; user id = myuser; password = mypassword; datanase = mydatabase")

MySqlCommand command = connection.CreateCommand();
command.commandtext = "Select Key,Value from mytable";
MySqlDataReader reader = command.Execute();
MyComboxBox.Items.Clear();
While (reader.read())
{
comoboval = new comboval(reader[key],reader[value]);
mycombo.items.add(comboval);
}

If you are only interested in the text you could forget the comboval class and just do
, mycombo.items.add(reader[value]);

If you aren't creating an inflatable dartboard.

They bash up the class and override the ToString() method return value.

PS that msi file comes with a nice swadge of examples.

PPS, this was off teh top of my head, so expect one or two syntax errors, probably Add instead of add for starters.

This discussion is closed to new replies.