Click here to Skip to main content
15,798,592 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am binding data to a combp box .I am retrieveing table name of a database and trying to populate it.When i populate it in gridview its working fine.But when i try the same for combo box its not working.

The code i used is as follows
string con = "Data Source=..\\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True";
sda = new SqlDataAdapter("select name from sysobjects where xtype='U'", con);
SqlCommandBuilder sc1 = new SqlCommandBuilder(sda);
DataTable db1 = new DataTable();
bd1.DataSource = db1;
dataGridView1.DataSource = bd1;
comboBox1.DataSource = bd1;

when i bind it to grid view it shows me the table names,but for combo box it returning the values as System.Data.DataRowViews

What should be done to correct the error.
Updated 2-Oct-11 23:32pm

1 solution

You need to add DisplayMember and Valuemember.

comboBox1.DisplayMember = "name";
               comboBox1.ValueMember = "name";

Hope be helpful,
Theingi Win
Share this answer
bsb25 3-Oct-11 4:37am    
where will i get the name value from?
bsb25 3-Oct-11 4:43am    
thanks..i got it...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900