private void button1_Click(object sender, EventArgs e) { StudentsDBDataContext sdc = new StudentsDBDataContext(); InfoStudent infstudent = new InfoStudent(); if (textBox1.ReadOnly == true) { InfoStudent inf = sdc.InfoStudents.SingleOrDefault(i => i.student_id == int.Parse(textBox1.Text)); inf.student_name = textBox2.Text; inf.parent_name = textBox4.Text; inf.phone_number = long.Parse(textBox3.Text); inf.addressOfStudent = textBox6.Text; inf.city = textBox5.Text; inf.country = textBox8.Text; inf.blood_group = textBox7.Text; sdc.SubmitChanges(); MessageBox.Show("record updated in table"); } else { infstudent.student_id = int.Parse(textBox1.Text); infstudent.student_name = textBox2.Text; infstudent.parent_name = textBox4.Text; infstudent.phone_number = long.Parse(textBox3.Text); infstudent.addressOfStudent = textBox6.Text; infstudent.city = textBox5.Text; infstudent.country = textBox8.Text; infstudent.blood_group = textBox7.Text; sdc.InfoStudents.InsertOnSubmit(infstudent); sdc.SubmitChanges(); MessageBox.Show("record inserted to table"); } }
private void Form1_Load(object sender, EventArgs e) { StudentsDBDataContext sdc = new StudentsDBDataContext(); dataGridView.DataSource = sdc.InfoStudents; }