The forums have permanently moved to This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 2 of 2

Thread: Add mysql database records to combobx

  1. #1

    Add mysql database records to combobx

    Hi everyone.

    I am new to c# 2005 and I would like to know how can I add mysql table records to combobox.


  2. #2
    hugeExplosions = true;
    This ones easy enough. You just need to add a SQL data reader to read the rows from your query

    Make sure you have imported the System.Data.SqlClient namespace

    // Create a new SQL connection - you can store this in the app.config in the connectionStrings node under appsettings and use ConfigurationManager to retrieve it if needs be. Just remember to add the reference to System.Configuration
    SqlConnection conn = new SqlConnection("server=localhost;uid=username;password=password");
    // Create a new SQL command to select the data using the new connection
                SqlCommand com = new SqlCommand("SELECT * FROM myTable", conn);
    // Create a SQL data reader var which will hold the result of the query
                SqlDataReader dr;
    // Open the connection
    // Execute the command into the datareader object
                dr = com.ExecuteReader();
    // Use a while loop to loop through any data rows
                while(dr.Read) {
                    // Get the ordinal for the column called 'ColumnName' and pass this to the GetString method (assuming you know what datatypes to expect from the column/columns) - add this value to the combobox
    // Close the connection
    I may be wrong with the combobox syntax as I just plucked this code out of my head, but apart from that it should work.
    MS Paint FTW!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Home About Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012