Click here to Skip to main content
15,037,928 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i use this code
C#
private void btnshow_Click(object sender, EventArgs e)
        {
            string connStr = "provider=Microsoft.Jet.OLEDB.4.0;Data Source='c:\\KBE\\solid piston1.xls';Extended Properties=Excel 8.0;";
            OleDbConnection MyConnection;
            DataSet ds1;
            OleDbDataAdapter MyCommand1;
            MyConnection = new OleDbConnection(connStr);
            MyCommand1 = new OleDbDataAdapter("select * from [INPUT$]", MyConnection);
            ds1 = new System.Data.DataSet();
            MyCommand1.Fill(ds1);
            DataTable dt1 = new DataTable();
            dt1 = ds1.Tables[0];
            
           cbf.Items.Insert(0, dt1.Rows[1]["Value"].ToString());
         
            textBox1.Text = dt1.Rows[2]["Value"].ToString();
            textBox2.Text = dt1.Rows[3]["Value"].ToString();
            comboBox2.Text = dt1.Rows[6]["Value"].ToString();



from this code i got only textbox value but not got comboBox text
so please tell me suggestion what change required in this programme

thanks
Posted
Updated 16-Jan-14 21:43pm
v2
Comments
sameer549 17-Jan-14 1:44am
   
check what values are there in combobox2, if combobox2 has a item with value dt1.Rows[6]["Value"].ToString(); then you will get it , or else u can also add items to combobox at runtime, like combobox2.items.add("")
dhaval082 17-Jan-14 1:51am
   
i have already add item like
10 HHE-FB
BDC OF 12 H
Karthik_Mahalingam 17-Jan-14 4:03am
   
post this btnshow_Click function full code...
Tejas Vaishnav 17-Jan-14 4:33am
   
Try to call your combobox DataBind() method after inserting data to it. some thing like this...
cbf.DataBind()

1 solution

ComboBox[^] class has got several properties[^], for example:
DataSource[^]
DisplayMember[^]
ValueMember[^]
You can use them to bind data ;)

C#
comboBox2.DataSource=dt1
comboBox2.DisplayMember = "Field1";
comboBox2.ValueMember = "Field2";
   

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