public List<ThongTinHS> findDSHSwithLop(int malop)
{
getConnection();
con.Open();
string sql = "select * from thongtinHS where malop=@malop";
SqlCommand cmd = new SqlCommand(sql,con);
cmd.Parameters.AddWithValue("malop", malop);
SqlDataReader rd = cmd.ExecuteReader();
List<ThongTinHS> dshs = new List<ThongTinHS>();
if (rd.Read())
{
ThongTinHS hs = new ThongTinHS();
hs.tenhs = Convert.ToString(rd["tenhs"]);
dshs.Add(hs);
}
con.Close();
return dshs;
}
Code em return một đối tượng là sao vậy?
↓
while (rd.Read())
2 Likes
cảm ơn nhiều ạ!!! em ms học nên làm theo cách kia.