Click here to Skip to main content
14,775,081 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I have used SQL Server Compact 4.0 Local as database, I have a table named department in which there is a single column only(Department - value like CSE,EEE). I need to show the value of Department column as the option of a DropDownList.
Please help.
Thank You
Posted

public DataTable Department()
{
string query = "select *from Department;
DataTable dt = fill(query);
return (dt);
}
public DataSet fill(string query)
{
con.Open();
SqlCommand cmd = new SqlCommand(query, con);

SqlDataAdapter adap = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adap.Fill(ds); con.Close();
return (ds);

}

DataTable dt = Department();
DropDown.Items.Clear();
DropDown.Items.Add("--Select--");
for (int i = 0; i < dt.Rows.Count; i++)
{
DropDown.Items.Add(dt.Rows[i]["Name"].ToString());
}



hope this will help you
   
Comments
Arindom_chanda 10-Sep-13 8:43am
   
Hi,
Thanks.
But Need code in VB.net
[no name] 10-Sep-13 8:46am
   
So translate it.
Dim dt1 As DataTable
       dt = General_fuction.RecordSearch("select * from Department ", "party")     
       Dim row As DataRow
       cmbdeptyname.Items.Clear()
       For Each row In dt.Rows
           For i = 0 To dt.Rows.Count
               cmbdeptyname.Items.Add(row(i).ToString())
               Exit For
           Next
       Next


This is simple code in vb.net show dropdown list item.
   

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