Question

  • Creator
    Topic
  • #2262349

    Microsoft .Net And MySQL

    Locked

    by ofentseboikanyo ·

    How do i populate Microsoft .Net combobox with information from MySQL database?

All Answers

  • Author
    Replies
    • #2542182

      Clarifications

      by ofentseboikanyo ·

      In reply to Microsoft .Net And MySQL

      Clarifications

    • #2541878

      There’s a few ways to do that.

      by tony hopkinson ·

      In reply to Microsoft .Net And MySQL

      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.

Viewing 1 reply thread