Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi frnds
i have a form and i have about five combox that i wil want to draw their dropdown item from a db the purpose is because i want user to be able to add or remove combobox item. heres the code i use to draw items
C#
..
try
{
SqlDataAdapter da = new SqlDataAdapter("select * from manag where category ='Light' ", con);
DataTable dt = new DataTable();
da.Fill(dt);
cbIlluminate.DataSource=dt;
cbIlluminate.DisplayMember="Choices";
con.Close();
}
Catch(System.Exception){}

i used the above code format for my five diferent comboboxes, this result in me creating five diferent datatable for each of them. Is this a good practice, i realy dont want my app to be slow because of this. Please need sugestions.
Thanks
Posted

1 solution

this
C#
you can use single datatable  for all .

try  this code 


//declare   datatable 
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
    {

    }


1.
try
{
SqlDataAdapter da = new SqlDataAdapter("select * from manag where category ='Light' ", con);
 dt=new datatable();
da.Fill(dt);
cbIlluminate.DataSource=dt;
cbIlluminate.DisplayMember="Choices";
con.Close();
}
Catch(System.Exception){}

2.
try
{
SqlDataAdapter da = new SqlDataAdapter("select * from manag where category ='Light' ", con);
 dt=new datatable();
da.Fill(dt);
cbIlluminate.DataSource=dt;
cbIlluminate.DisplayMember="Choices";
con.Close();
}
Catch(System.Exception){}

3.
try
{
SqlDataAdapter da = new SqlDataAdapter("select * from manag where category ='Light' ", con);
 dt=new datatable();
da.Fill(dt);
cbIlluminate.DataSource=dt;
cbIlluminate.DisplayMember="Choices";
con.Close();
}
Catch(System.Exception){}
 
Share this answer
 
Comments
Ese ochuko 9-Jul-13 13:36pm    
Tanks bro

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