There are a number of ways to do this:
1) You could use a DataAdapter and DataTable:
SqlDataAdapter da = new SqlDataAdapter("SELECT stuid FROM attendance", myconn);
DataTable dt = new DataTable();
da.Fill(dt);
ddlstuid.Items.Clear();
ddlstuid.DataSource = dt;
2) You could construct a list and use that:
try
{
cmd = new SqlCommand("select stuid from attendance", myconn);
myconn.Open();
ddlstuid.Items.Clear();
dr = cmd.ExecuteReader();
List<object> list = new List<object>();
if (dr != null)
{
while (dr.Read())
{
list.Add(dr["stuid"]);
}
}
myconn.Close();
ddlstuid.DataSource = list;
}
catch (Exception e1)
{
Label45.Text = "Error ocurred" + e1;
}
Personally, I prefer the former...