private void Update(int id) { using (SampleDataContext context = new SampleDataContext()) { guardian g = context.guardians.Where(x => x.id == id).SingleOrDefault(); int s_id = Convert.ToInt32(txtStd_id.Text); if (context.students.Where(x => x.std_id == s_id).Single() != null) { g.g_Fname = txtFname.Text; g.g_Lname = txtLname.Text; g.g_Address = txtAddress.Text; g.std_id = s_id; context.SubmitChanges(); GetData(); Clear(); } else { Response.Write("<script>alert('Student ID Not Found!!')</script>"); } } }
protected void dltGuardian_Click(object sender, EventArgs e) { int i = Convert.ToInt32((sender as LinkButton).CommandArgument); using (SampleDataContext context = new SampleDataContext()) { guardian g = context.guardians.Where(x => x.id == i).SingleOrDefault(); g.std_id = null; context.SubmitChanges(); context.guardians.DeleteOnSubmit(g); context.SubmitChanges(); GridView2.DataSource = null; } GetData(); Clear(); }
protected void Delete_Click(object sender, EventArgs e) { HideGrid(); hf1.Value = (sender as LinkButton).CommandArgument; i = Convert.ToInt32(hf1.Value); using (SampleDataContext context = new SampleDataContext()) { guardian g = context.guardians.Where(x => x.std_id == i).SingleOrDefault(); if (g != null) { g.std_id = null; context.SubmitChanges(); } student std = context.students.SingleOrDefault(x => x.std_id == i); context.students.DeleteOnSubmit(std); context.SubmitChanges(); Clear(); GetData(); } }
private void storeData() { student std = new student { std_Fname = "Muhammad", std_class = 16, std_Lname = "Zaman" }; List <student> lst = new List <student>(); for (int i = 0; i < 999; i++) { lst.Add(std); } using (SampleDataContext dbcontext = new SampleDataContext()) { dbcontext.students.InsertAllOnSubmit(lst); dbcontext.SubmitChanges(); } }
private void InsertOrUpdate(int ind) { using (SampleDataContext dbContext = new SampleDataContext()) { if (ind == 0) { student newstd = new student() { std_Fname = txtFirstName.Text, std_Lname = txtLastName.Text, std_class = Convert.ToInt32(txtClass.Text) }; dbContext.students.InsertOnSubmit(newstd); } else { student student_obj = dbContext.students.Single(x => x.std_id == ind); if (student_obj == null) { Response.Write("<script>alert('Not Found')</script>"); } else { student_obj.std_id = ind; student_obj.std_Fname = txtFirstName.Text; student_obj.std_Lname = txtLastName.Text; student_obj.std_class = Convert.ToInt32(txtClass.Text); } } dbContext.SubmitChanges(); Response.Write("<script>alert('Changes Saved!')</script>"); Clear(); GetData(); RowWork(); } }
protected void adGuardianBtn_Click(object sender, EventArgs e) { if (isValid()) { using (SampleDataContext dbcontext = new SampleDataContext()) { guardian newg = new guardian() { g_Fname = txtGuardianFName.Text, g_Lname = txtGuardianLname.Text, g_Address = txtGuardianAddress.Text, std_id = Convert.ToInt32(hf2.Value) }; dbcontext.guardians.InsertOnSubmit(newg); dbcontext.SubmitChanges(); Response.Redirect("~/Guardian.aspx"); } } else { Response.Write("<script>alert('Cannot Process Request due to validation error')</script>"); } }