0

In my winodws application, i want to add one column of a table in combo box.

The code below gets the Product Name from the database as dataset.

public DataSet GetAllItems()
{
    DataSet dataSet = new DataSet();
    // Create connection object
    OleDbConnection oleConn = new OleDbConnection(connString);
    try
    {
        oleConn.Open();
        string sql = "SELECT [Product Name] FROM [Product]";
        OleDbDataAdapter dataAdapter = new OleDbDataAdapter(sql, oleConn);
        dataAdapter.Fill(dataSet, "Product");
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.ToString());
    }
    finally
    {
        oleConn.Close();
    }
    if (dataSet.Tables.Count <= 0)
        return null;
    else
        return dataSet;
}

Now how can i add those items in dataset to the combo box.

Amrit Sharma
  • 1,906
  • 8
  • 45
  • 75

1 Answers1

0

Try:

DataSet ds = GetAllItems();
YourcomboBox.DataSource = ds.Tables[0];
YourcomboBox.DisplayMember = "Product Name";
4b0
  • 21,981
  • 30
  • 95
  • 142