private void btnupdate_Click(object sender, RoutedEventArgs e) { EmployeeDataContext dbc = new EmployeeDataContext(); Employee e1 = dbc.Employees.SingleOrDefault(emp => emp.EmpNo == Convert.ToInt32(txtEmpId.Text)); if (e1 != null) { try { e1.EmpName = txtEmpName.Text.ToString(); e1.Basic = Convert.ToDouble(txtBasic.Text); e1.DeptNo = Convert.ToInt32(txtDeptNo.Text); dbc.SubmitChanges(); MessageBox.Show("Done"); } catch (Exception Ex) { MessageBox.Show(Ex.Message); } } else { MessageBox.Show("Employee not Present"); } }
private void btnInsert_Click(object sender, RoutedEventArgs e) { EmployeeDataContext dbc = new EmployeeDataContext(); Employee e1 = new Employee(); try { e1.EmpNo = Convert.ToInt32(txtEmpId.Text); e1.EmpName = txtEmpName.Text.ToString(); e1.Basic = Convert.ToDouble(txtBasic.Text); e1.DeptNo = Convert.ToInt32(txtDeptNo.Text); dbc.Employees.InsertOnSubmit(e1); dbc.SubmitChanges(); MessageBox.Show("Done"); } catch { } }
private void btnDelete_Click(object sender, RoutedEventArgs e) { EmployeeDataContext dbc = new EmployeeDataContext(); Employee e1 = dbc.Employees.SingleOrDefault(emp => emp.EmpNo == Convert.ToInt32(txtEmpId.Text)); if (e1 != null) { try { dbc.Employees.DeleteOnSubmit(e1); dbc.SubmitChanges(); MessageBox.Show("Done"); } catch (Exception Ex) { MessageBox.Show(Ex.Message); } } else { MessageBox.Show("Employee not Present"); } }