Hello All,

Can any one tell me how we bind data to a ComboBox from a dataset?

Thanks for your precious help

For binding a ComboBox we have to set its display as well as value member. :)

comboBox1.DataSource=null;
//Your Code for connecting to database and retrieving data in dataset1
//You have two columns in dataSet1.Tables[0] ,, "id", "name"

comboBox1.DataSource=dataSet1.Tables[0];
comboBox1.DisplayMember="name";
comboBox1.ValueMember="id";

//Rest of the code

Edited 5 Years Ago by abelLazm: n/a

Thanks for your reply... Saikalyankumar The link you provided is not opening... abelLazm Thanks for your help, how to add items in comboBox after binding?

Edited 5 Years Ago by bahed121: n/a

.....how to add items in comboBox after binding?

dear bahed after adding these lines you data will automatically populate in combobox there is no need to add any thing like combobox.items.add();

U, can loop through each row in the Table of the Dataset and by using the combobox.items.add, u can add the items. an ex: code is here

for (int i = 0; i < dt.Rows.Count - 1; i++)
                {
                    DataRow dr = dt.Rows[i];
                    drpllist_ServerName1.Items.Add(dr["Name"].ToString());
                }

Thanks abellazm your post really worked for me...Saikalyankumar your provided link is also very useful thanks again

This question has already been answered. Start a new discussion instead.