private void btnnewsave_Click(object sender, EventArgs e) { int seq_val = 0; using (proadmin_v1Entities db = new proadmin_v1Entities()) { var seq = db.GetNextSequenceValue(); int?nextSequenceValue = seq.Single(); seq_val = nextSequenceValue.Value; } if (txtnewfullname.Text == "" || txtnewlastname.Text == "" || txtnewnic.Text == "" || dtpnewdob.Text == "" || txtnewhomwaddress.Text == "" || txtnewhometell.Text == "" || txtnewfathername.Text == "" || txtnewparentsname.Text == "" || cmbnewolschool.Text == "" || cmbnewalschool.Text == "" || cmbnewbatch.Text == "" || cmbnewscol.Text == "" || cmbnewgender.Text == "" || txtnewstaytell.Text == "" || txtnewstayaddress.Text == "") { message_popup_ok("Empty fields found."); } else { string regid = cmbnewbatch.Text + "01" + seq_val; model_students.regid = regid; model_students.Firstname = txtnewfullname.Text; model_students.Lastname = txtnewlastname.Text; model_students.Nic = txtnewnic.Text; model_students.Dob = dtpnewdob.Text; model_students.home_address = txtnewhomwaddress.Text; model_students.Home_tell = txtnewhometell.Text; model_students.Staying_address = txtnewstayaddress.Text; model_students.Stay_home_tell = txtnewstaytell.Text; model_students.Father_name = txtnewfathername.Text; model_students.Parents_contact = txtnewparentsname.Text; model_students.Ol_School = cmbnewolschool.Text; model_students.Al_school = cmbnewalschool.Text; model_students.Ol_result = txtnewolresult.Text; model_students.JoinDate = txtnewjoiningdate.Text; model_students.Batch = cmbnewbatch.Text; model_students.Gender = cmbnewgender.Text; model_students.Scholarship = cmbnewscol.SelectedItem.ToString(); using (proadmin_v1Entities db = new proadmin_v1Entities()) { if (model_students.Id == 0)//Insert { db.basicdata_student.Add(model_students); } else //Update { db.Entry(model_students).State = EntityState.Modified; } db.SaveChangesAsync(); clear_fields(); message_popup_ok("Data Record Saved!"); populate_student_data_grid_view(); //Reset normal after changes done model_students.Id = 0; btnSave.Text = "Save"; txtmessage.Text = "New Student Reg ID : '" + regid + "'"; txtmessagbarcode.Text = regid; } } }