Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
C#
con.Open();
         using (con)
         {
             SqlDataReader dr;
             dr = cmd.ExecuteReader();
             if (dr.HasRows)
             {
                 while (dr.Read())
                 {
                     T c = Activator.CreateInstance<t>(); //in generic class we activate instance
                     PropertyInfo[] p = typeof(T).GetProperties();
                    // foreach (PropertyInfo item in p)
                    // { }
                        // object o = dr[Item.Name];
                        
                            // item.SetValue(c, o, null);
                         Inventory inv = new Inventory();
                         inv.ItemId = Convert.ToInt32(dr["ItemId"]);
                         inv.ItemName = (dr["ItemName"]).ToString();
                         inv.ItemPrice = Convert.ToInt32(dr["ItemPrice"]);
                         inv.ItemQuantity = Convert.ToInt32(dr["ItemQuantity"]);
                         inv.ItemDescription = (dr["Itemdescription"]).ToString();

                         lst.Add(inv);                  

                 }
             }
             return lst;
Posted
Updated 4-Apr-14 7:11am
v2

use datatable and data adapter for that..

data adapter get the data.....datatable will hold the data...

for example dt is our datatable then the code is...

combobox1.datasource=dt;
combobox1.displaymemer="col here ";
combobox1.valuemember= "col here";

colhere is the column you want to display....

hope that answer the question
 
Share this answer
 
Hi, this way...
C#
combobox1.datasource = lst; //list you have filled from db
combobox1.DisplayMember = "ItemName";//name of column here (property) of list to be display 
combobox1.ValueMember = "ItemID";

Happy Coding!
:)
 
Share this answer
 
I don't see your code to bind the combobox; however, the following link should help you. http://msdn.microsoft.com/en-us/library/x8ybe6s2(v=vs.90).aspx[^]

Setting the DisplayMember property to one of your columns will show that column and the ValueMember property to a different column if you need to.
 
Share this answer
 
get the list data first

and then add a list in to

for update every signle value

C#
for(int i=0;i<=dt.rows.count;i++)
{
combox.items.add(dt.rows[0][i].tostring()

}


for bind a datasource to control
C#
combobox1.datasource=dt;
combobox1.displaymemer="col here ";
combobox1.valuemember= "col here";
 
Share this answer
 

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