In C Create a form to manage student data including SID name

In C#, Create a form to manage student data, including SID, name, totalCredits, GPA, birthdate, and major, stored in a data file. It should have a list box to show all the students in the data file. It should allow one to update any student in the list.

Solution

public partial class Form1 : Form
    {
        List<student> studentList = new List<student>();
        public Form1()
        {
            InitializeComponent();
        }
        //Lod Listbox with students by parsing XML data file
        private void Form1_Load(object sender, EventArgs e)
        {
            XDocument studentDataFile = XDocument.Load(\"StudentData.xml\");

            studentList = new List<student>();

            foreach (XElement item in studentDataFile.Descendants(\"student\"))
            {
                studentList.Add(new student
                {
                    sid = item.Element(\"name\").Value,
                    name = item.Element(\"sid\").Value,
                    totalCredits = item.Element(\"TotalCredits\").Value,
                    gpa = item.Element(\"GPA\").Value,
                    birthDate = item.Element(\"BirthDate\").Value,
                    major = item.Element(\"Major\").Value
                });
            }
            listBox1.DataSource = studentList;
            listBox1.DisplayMember = \"name\";
            listBox1.ValueMember = \"sid\";
        }
        //On selecting a Student from listbox display his details on textboxes
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            student stdObject = studentList.FirstOrDefault(item => item.sid == e.ToString());
            textBox1.Text = stdObject.sid;
            //Similarly display other fiedsS
        }
    }
    public class student
    {
        public string sid;
        public string name;
        public string totalCredits;
        public string gpa;
        public string birthDate;
        public string major;
    }

//Sample code to update XML file

XDocument xmlFile = XDocument.Load(\"StudentData.xml\");
var query = from item in xmlFile.Elements(\"Students\").Elements(\"Student\")  
            select item;
foreach (XElement student in query)
{
    student.Attribute(\"sid\").Value = \"NewValue\";
}
xmlFile.Save(\"StudentData.xml\");

In C#, Create a form to manage student data, including SID, name, totalCredits, GPA, birthdate, and major, stored in a data file. It should have a list box to s
In C#, Create a form to manage student data, including SID, name, totalCredits, GPA, birthdate, and major, stored in a data file. It should have a list box to s

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site