Code em return một đối tượng là sao vậy?

 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;
        
    }

while (rd.Read())
2 Likes

cảm ơn nhiều ạ!!! em ms học nên làm theo cách kia.

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?