public void AddDataRowSach(Sach s) { DataRow dr = DTS.NewRow(); dr["maSach"] = s.maSach; dr["tenSach"] = s.tenSach; dr["soLuong"] = s.soLuong; dr["maTG"] = s.maTG; dr["maNXB"] = s.maNXB; DTS.Rows.Add(dr); }
public void EditDataRowSach(Sach s) { foreach (DataRow i in DTS.Rows) { if (Convert.ToInt32(i["maSach"].ToString()) == s.maSach) { CSDL.Instance.DTS.Rows.Remove(i); DataRow dr = DTS.NewRow(); dr["tenSach"] = s.tenSach; dr["soLuong"] = s.soLuong; dr["maTG"] = s.maTG; dr["maNXB"] = s.maNXB; DTS.Rows.Add(dr); return; } } }
//Method takes values from Student object and converts into XML format public void ExportToXml(Student student, string filename, bool alsoread) { //Add student object to Dataset DataTable DTS; if (StudentDataSet == null) { StudentDataSet = new DataSet("Students"); DTS = new DataTable("Student"); DTS.Columns.Add("FirstName"); DTS.Columns.Add("Surname"); DTS.Columns.Add("Email"); DTS.Columns.Add("Phone"); DTS.Columns.Add("AddressLine1"); DTS.Columns.Add("AddressLine2"); DTS.Columns.Add("County"); DTS.Columns.Add("City"); DTS.Columns.Add("Graduatelevel"); DTS.Columns.Add("Course"); DTS.Columns.Add("StudentNumber"); StudentDataSet.Tables.Add(DTS); } DTS = StudentDataSet.Tables["Student"]; DataRow rowstu = DTS.NewRow(); rowstu["FirstName"] = student.FirstName; rowstu["Surname"] = student.Surname; rowstu["Email"] = student.Email; rowstu["Phone"] = student.Phone; rowstu["AddressLine1"] = student.AddressLine1; rowstu["AddressLine2"] = student.AddressLine2; rowstu["County"] = student.County; rowstu["City"] = student.City; rowstu["Graduatelevel"] = student.GraduateLevel; rowstu["Course"] = student.Course; rowstu["StudentNumber"] = student.StudentNumber; DTS.Rows.Add(rowstu); DTS.AcceptChanges(); //To export to XML if (alsoread) { StudentDataSet.ReadXml(filename, XmlReadMode.InferSchema); } StudentDataSet.WriteXml($"{filename}"); }