protected void btnDeleteCust_Click(object sender, EventArgs e) { try { GRASSLYLIB.EmmasDataSet.CustomerCRUDRow row = dsCust.CustomerCRUD.FindByid(id); row.Delete(); GRASSLYLIB.EmmasDataSetTableAdapters.CustomerCRUDTableAdapter daCust = new GRASSLYLIB.EmmasDataSetTableAdapters.CustomerCRUDTableAdapter(); daCust.Update(dsCust.CustomerCRUD); dsCust.AcceptChanges(); dsCust.CustomerCRUD.Clear(); daCust.Fill(dsCust.CustomerCRUD); Response.Redirect("~/Customer.aspx"); } catch (Exception ex) { lblCust.ForeColor = System.Drawing.Color.Red; if (ex.Message.Contains("fk")) { lblCust.Text = "You can't delete this customer, they have other records."; } else { lblCust.Text = ex.Message; } } }
protected void btnCreateCust_Click(object sender, EventArgs e) { //try //{ DataRow r; r = dsCust.CustomerCRUD.NewRow(); if (id == -1) { r = dsCust.CustomerCRUD.NewRow(); r["custFirst"] = this.txtFirst.Text; r["custLast"] = this.txtLast.Text; r["custPhone"] = this.txtPhone.Text; r["custEmail"] = this.txtEmail.Text; r["custAddress"] = this.txtAddress.Text; r["custCity"] = this.txtCity.Text; r["custPostal"] = this.txtPostal.Text; dsCust.CustomerCRUD.Rows.Add(r); } else { dsCust.CustomerCRUD.FindByid(id).custFirst = txtFirst.Text; dsCust.CustomerCRUD.FindByid(id).custLast = txtLast.Text; dsCust.CustomerCRUD.FindByid(id).custPhone = txtPhone.Text; dsCust.CustomerCRUD.FindByid(id).custEmail = txtEmail.Text; dsCust.CustomerCRUD.FindByid(id).custAddress = txtAddress.Text; dsCust.CustomerCRUD.FindByid(id).custCity = txtCity.Text; dsCust.CustomerCRUD.FindByid(id).custPostal = txtPostal.Text; } GRASSLYLIB.EmmasDataSetTableAdapters.CustomerCRUDTableAdapter daCust = new GRASSLYLIB.EmmasDataSetTableAdapters.CustomerCRUDTableAdapter(); daCust.Update(dsCust.CustomerCRUD); dsCust.AcceptChanges(); dsCust.CustomerCRUD.Clear(); daCust.Fill(dsCust.CustomerCRUD); Response.Redirect("~/Customer.aspx"); }