public List <qlbhDTO> GetNhanVien(string sql) { List <qlbhDTO> list = new List <qlbhDTO>(); int maLoaiSp; string tenLoaiSp; dp.Connect(); try { SqlDataReader dr = dp.executeReader(sql); while (dr.Read()) { maLoaiSp = dr.GetInt32(0); tenLoaiSp = dr.GetString(1); qlbhDTO ql = new qlbhDTO(maLoaiSp, tenLoaiSp);//-> gọi DTO, DTO lấy dữ liệu từ Data list.Add(ql); } dr.Close(); return(list);// trả về List đã có dữ liệu } catch (SqlException ex) { throw ex; } finally { dp.DisConnect(); } }
public int add(qlbhDTO ql) { try { return(new qlbhDAL().add(ql)); } catch (SqlException ex) { throw ex; } }
private void btnAdd_Click(object sender, EventArgs e) { int maLoaiSp; string tenLoaiSp; maLoaiSp = Convert.ToInt32(txtMaSp.Text); tenLoaiSp = Convert.ToString(txtTenSp.Text); qlbhDTO ql = new qlbhDTO(maLoaiSp, tenLoaiSp); int i = new qlbhBUS().add(ql); dvgQLBH.DataSource = GetNhanVien(); }
//public List<qlbhDTO> GetNhanVien(string sql); public int add(qlbhDTO ql) { List <SqlParameter> paras = new List <SqlParameter>(); paras.Add(new SqlParameter("@MaSp", ql.MaLoaiSp)); paras.Add(new SqlParameter("@TenLoaiSp", ql.TenLoaiSp)); try { return(dp.executeNonQuery("addSP", System.Data.CommandType.StoredProcedure, paras)); } catch (SqlException ex) { throw ex; } }