public List<Student> GetList()
{
string sql = "select * from Student";
using (conn = new SqlConnection(connectionstring))
{
conn.Open();
List<Student> list = new List<Student>();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
Student stu = new Student();
stu.ID = Convert.ToInt32(sdr[0]);
stu.Name = sdr[1].ToString();
stu.Sex = Convert.ToInt32(sdr[2]);
stu.Age = Convert.ToInt32(sdr[3]);
list.Add(stu);
}
return list;
}
}