01/10/2018, 12:09

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;
        
    }
Dark.Hades viết 14:09 ngày 01/10/2018

if (rd.Read())

while (rd.Read())
Tuân Nguyễn viết 14:14 ngày 01/10/2018

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

Bài liên quan
0