Click here to Skip to main content
15,896,915 members

Data not binding to dropdown list

Revision 1
private void load_uname()
{
username.Items.Clear();

SqlConnection con = new SqlConnection(constring);
con.Open();
string sql = "select [uname] from user_registration where usergroup ='" + usertype.SelectedValue.ToString() + "' ";
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataReader dr;
dr = cmd.ExecuteReader();
username.Items.Add("<------Select---->");
while (dr.Read())
{

username.Items.Add(new ListItem(dr[0].ToString()));
}
}


this is my code which is not working if i put my query statically like this "select [uname] from user_registration where usergroup ='owners'", it's working but the above query in the code not fetching the data!!
Posted 22-Jan-13 1:12am by Member 9378829.
  Print Answers RSS
Top Experts
Last 24hrsThis month