public List <PhongHocDTO> getAll() { List <PhongHocDTO> phs = new List <PhongHocDTO>(); conn.Open(); string sql = "select * from phonghoc"; SqlCommand cmd = new SqlCommand(sql, conn); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { PhongHocDTO ph = PhongHocMapper.map(dr); phs.Add(ph); } conn.Close(); return(phs); }
public PhongHocDTO findById(string id) { conn.Open(); string sql = "select * from phonghoc where id_PH = @id"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("id", id); SqlDataReader dr = cmd.ExecuteReader(); PhongHocDTO ph = null; while (dr.Read()) { ph = PhongHocMapper.map(dr); } conn.Close(); return(ph); }
public List <PhongHocDTO> findByName(string name) { conn.Open(); List <PhongHocDTO> phs = new List <PhongHocDTO>(); string sql = "select * from phonghoc where ten_PH like concat('%',@ten,'%')"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("ten", name); SqlDataReader dr = cmd.ExecuteReader(); PhongHocDTO ph = null; while (dr.Read()) { ph = PhongHocMapper.map(dr); phs.Add(ph); } conn.Close(); return(phs); }