public int Delete(int id) { // Kiem tra xem lop do co sv nao khong List <Lop> ds = Select("id=" + id); if (ds.Count > 0) { Lop l = ds[0]; if (l.DanhSach().Count > 0) { // Khong the xoa return(-2); } } String query = "Delete tbLop Where id=" + id.ToString(); int dem = da.Write(query); return(dem); }
public List <Lop> Select(String condition) { String query = "Select * from tbLop Where " + condition; DataTable tb = da.Read(query); if (tb != null && tb.Rows.Count > 0) { List <Lop> ds = new List <Lop>(); foreach (DataRow r in tb.Rows) { Lop sv = new Lop(); sv.ID = int.Parse(r["ID"].ToString()); sv.Ten = r["Ten"].ToString(); ds.Add(sv); } return(ds); } else { return(null); } }