C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » .NET »

How to populate combobox from dataset or .xls file


Posted Date: 26 Jun 2009      Posted By: shanker      Member Level: Silver     Points: 1   Responses: 2



hi all,

I tried to bind datas with comboBox in windows application. But I am getting only "System.Data.DataRow" in my comboBox.

I used the following code

OleDbDataAdapter Oa = new OleDbDataAdapter("Select * From [" + sheet+"]", cn);
DataSet ds = new DataSet();
Oa.TableMappings.Add("Table", "[" + sheet + "]");
Oa.Fill(ds);
DataViewManager dviewmanager = new DataViewManager();
dviewmanager = ds.DefaultViewManager;
comboBox2.DataSource =ds.Tables[0];
//comboBox2.ValueMember = "s#no";
comboBox2.DisplayMember = "roll";

But I am getting "System.data.DataRow" in my comboBox.

So,How to bind data with comboBox?

Thanks
B.shanker





Responses

Author: Anil Kumar Pandey    26 Jun 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

hi,

refer this..


comboBox2.DataSource = ds.Tables[0];
comboBox2.ValueMember = ds.Tables[0].[0]["s#no"];
comboBox2.DisplayMember = ds.Tables[0].[0]["roll"];


Thanks & Regards
Anil Kumar Pandey



Author: satya    26 Jun 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

comboBox2.DataSource =ds.Tables[0];
comboBox2.DataTextField = "sno";
comboBox2.DataValueField = "roll";
comboBox2.DataBind();



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : How to change number format ?
Previous : How to populate combobox from dataset or .xls file
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use