المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : am tryin to fill the dropdwn list from the database...but it is not displayin any values..plz help me



C# Programming
08-25-2009, 12:40 PM
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
string connection1 = ConfigurationManager.AppSettings["conn"];
OleDbConnection con1 = new OleDbConnection(connection1);
con1.Open();



OleDbDataReader dr;

string query = "select DISTINCT DEPARTMENT from TIME_DETAILS ";
OleDbDataAdapter da1 = new OleDbDataAdapter(query,con1);
DataSet ds1 = new DataSet();
//da1.Fill(ds1);
OleDbCommand cmd = new OleDbCommand(query,con1);
da1.SelectCommand=cmd;
da1.Fill(ds1,"dept");
DataTable dep=ds1.Tables["dept"];
dr = cmd.ExecuteReader();
DropDownList2.DataSource=dep;
if(dep.Rows.Count>0)
{
foreach (DataRow row in dep.Rows )
{DropDownList2.Items.Add(row[0].ToString());}

}
//while (dr.Read())
//{
//DropDownList2.Items.Add(dr[0].ToString());
//DropDownList2.DataValueField.Insert(dr[0]);
// DropDownList2.Items.Add(New ListItem(dr[0].ToString())));
// }



}