public static void LoadStudentsFromXMLFile(String fileName) { List<Student> students = new List<Student>(); XmlDocument document = new XmlDocument(); document.Load(fileName); XmlNodeList nodes = document.SelectNodes("//Students//Student"); foreach (XmlNode node in nodes) { Student student = new Student(); XmlNode Child = node.FirstChild; int id; if (Int32.TryParse(Child.InnerText, out id)) student.Id = id; Child = Child.NextSibling; student.Name = Child.InnerText; Child = Child.NextSibling; student.Grade = Child.InnerText; Child = Child.NextSibling; student.Branch = Child.InnerText; Child = Child.NextSibling; student.State = Child.InnerText; students.Add(student); } Student.InsertStudents(students); }
public static bool AddStudent(Student student) { String sqlQuery = String.Format("INSERT INTO Student VALUES({0},'{1}','{2}','{3}','{4}')", student.Id, student.Name, student.Grade, student.Branch, student.State); String conString = ConfigurationManager.ConnectionStrings["CollegeDB"].ConnectionString; SqlConnection connection = new SqlConnection(conString); connection.Open(); SqlCommand command = new SqlCommand(sqlQuery, connection); command.ExecuteScalar(); connection.Close(); command.Dispose(); connection.Dispose(); return true; }