protected void Button1_Click(object sender, EventArgs e) { //try //{ DataRow r; r = dsEmp.EmployeeCRUD.NewRow(); if (id == -1) { r = dsEmp.EmployeeCRUD.NewRow(); r["empFirst"] = this.txtFirst.Text; r["empLast"] = this.txtLast.Text; r["posID"] = this.ddlPosition.SelectedValue; dsEmp.EmployeeCRUD.Rows.Add(r); } else { dsEmp.EmployeeCRUD.FindByid(id).empFirst = txtFirst.Text; dsEmp.EmployeeCRUD.FindByid(id).empLast = txtLast.Text; dsEmp.EmployeeCRUD.FindByid(id).posID = Convert.ToInt32(ddlPosition.SelectedValue); } GRASSLYLIB.EmmasDataSetTableAdapters.EmployeeCRUDTableAdapter daEmp = new GRASSLYLIB.EmmasDataSetTableAdapters.EmployeeCRUDTableAdapter(); daEmp.Update(dsEmp.EmployeeCRUD); dsEmp.AcceptChanges(); dsEmp.EmployeeCRUD.Clear(); daEmp.Fill(dsEmp.EmployeeCRUD); Response.Redirect("~/Employee.aspx"); }
protected void btnDeleteEmp_Click(object sender, EventArgs e) { try { GRASSLYLIB.EmmasDataSet.EmployeeCRUDRow row = dsEmp.EmployeeCRUD.FindByid(id); row.Delete(); GRASSLYLIB.EmmasDataSetTableAdapters.EmployeeCRUDTableAdapter daEmp = new GRASSLYLIB.EmmasDataSetTableAdapters.EmployeeCRUDTableAdapter(); daEmp.Update(dsEmp.EmployeeCRUD); dsEmp.AcceptChanges(); dsEmp.CustomerCRUD.Clear(); daEmp.Fill(dsEmp.EmployeeCRUD); Response.Redirect("~/Employee.aspx"); } catch (Exception ex) { lblEmp.ForeColor = System.Drawing.Color.Red; if (ex.Message.Contains("fk")) { lblEmp.Text = "You can't delete this employee, they have other records."; } else { lblEmp.Text = ex.Message; } } }
static EmployeeCreate() { GRASSLYLIB.EmmasDataSetTableAdapters.EmployeeCRUDTableAdapter daEmp = new GRASSLYLIB.EmmasDataSetTableAdapters.EmployeeCRUDTableAdapter(); daEmp.Fill(dsEmp.EmployeeCRUD); }