public NhacungcapCollection() { DataTable dt = DataAccess.ViewForGridView("Nhacungcap_ViewAll"); foreach (DataRow dr in dt.Rows) { Nhacungcap ncc = new Nhacungcap(); ncc.NhacungcapID = int.Parse(dr["NhacungcapID"].ToString()); ncc.Tennhacungcap = dr["Tennhacungcap"].ToString(); ncc.Diachi = dr["Diachi"].ToString(); ncc.Dienthoai =dr["Dienthoai"].ToString(); lst.Add(ncc); } }
public static List<Nhacungcap> ViewAll() { if (conn.State == ConnectionState.Open) conn.Close(); conn.Open(); SqlCommand sc = new SqlCommand("Nhacungcap_ProcViewAll", conn); sc.CommandType = CommandType.StoredProcedure; SqlDataReader reader = sc.ExecuteReader(); List<Nhacungcap> lstNcc = new List<Nhacungcap>(); while (reader.Read()) { Nhacungcap ncc = new Nhacungcap(); ncc.NhacungcapID = (reader["NhacungcapID"] != null ? int.Parse(reader["NhacungcapID"].ToString()) : 0); ncc.Tennhacungcap = (reader["Tennhacungcap"] != null ? reader["Tennhacungcap"].ToString() : ""); ncc.Diachi = (reader["Diachi"] != null ? reader["Diachi"].ToString() : ""); ncc.Dienthoai = (reader["Dienthoai"] != null ? reader["Dienthoai"].ToString() : ""); lstNcc.Add(ncc); } reader.Close(); conn.Close(); return lstNcc; }