Microsoft Access - Bind Dataset with ComboBox

This is a simple article which describes how to bind a dataset to a comboBox.

In this article we assume that user know how to fill a dataset object with desired Data.

If you don't know how to fill a dataset, here is a simple step as follows:

1. Suppose you are using Access database named "ComboDetail".

2. This contains a Table called "Categories"

3. Table contains two fields ProductDetail and ProductPrice.

In your c# code window first add reference to Data namespace like this:

using System.Data.Oledb;

So now you are ready.


//create a oledb connection
oleDbConnection cn=new oleDbConnection(sConnectionString);
//create data adapter
oleDbdataAdapter adp=new oleDbdataAdapter("select * from Categories",cn);
//Create a Dataset
DataSet ds=new DataSet();
// NOW you hav a data set which contains the table "Categories"
//bind it with comboBox1 as follows

// you can also associate other Value to the same combobox like this:
//set the display index for first item to be displayed

// Now you are done with it... I hope this will sort some of your problem. I have taken fullcare for the correctness of the code. if something still is confusing please feel free to discuss.

By Ajay Arora   Popularity  (8578 Views)