protected void Page_Load(object sender, EventArgs e) { customerTableAdapter daCustomer = new customerTableAdapter(); if (!User.Identity.IsAuthenticated) { Response.Redirect("~/Login.aspx"); } daCustomer.Update(dsCustomer); daCustomer.Fill(dsCustomer.customer); foreach (DataRow r in dsCustomer.customer) { TableRow tblRow = new TableRow(); TableCell linkButtons = new TableCell(); TableCell firstName = new TableCell(); TableCell lastName = new TableCell(); TableCell phoneNumber = new TableCell(); TableCell custAddress = new TableCell(); TableCell custCity = new TableCell(); TableCell custPostal = new TableCell(); TableCell emailAddress = new TableCell(); linkButtons.Controls.Add(new LinkButton { Text = "Edit", PostBackUrl = "Customer_Edit.aspx?val=" + r.ItemArray[0].ToString() }); linkButtons.Controls.Add(new Literal { Text = "<br />" }); linkButtons.Controls.Add(new LinkButton { Text = "Delete", PostBackUrl = "Customer_Delete.aspx?val=" + r.ItemArray[0].ToString() }); firstName.Text = r.ItemArray[1].ToString(); lastName.Text = r.ItemArray[2].ToString(); phoneNumber.Text = r.ItemArray[3].ToString(); custAddress.Text = r.ItemArray[4].ToString(); custCity.Text = r.ItemArray[5].ToString(); custPostal.Text = r.ItemArray[6].ToString(); emailAddress.Text = r.ItemArray[7].ToString(); tblRow.Cells.Add(linkButtons); tblRow.Cells.Add(firstName); tblRow.Cells.Add(lastName); tblRow.Cells.Add(phoneNumber); tblRow.Cells.Add(custAddress); tblRow.Cells.Add(custCity); tblRow.Cells.Add(custPostal); tblRow.Cells.Add(emailAddress); this.tblCustomers.Rows.Add(tblRow); } this.ddlManagement.Items[0].Attributes.Add("style", "color:#009900"); this.ddlManagement.Items[0].Attributes.Add("disabled", "disabled"); }
private void Save() { try { customerTableAdapter daCustomer = new customerTableAdapter(); daCustomer.Update(dsCustomer.customer); // Call update method on the service adapter so it updates the table in memory ( All changes made are applied - CRUD) dsCustomer.AcceptChanges(); // Call accept method on the dataset so it update the chanmges to the database lblStatus.Text = "Record Successfully Updated"; } catch { dsCustomer.RejectChanges(); lblStatus.Text = "Unable to Update Record"; } }
private void Save() { customerTableAdapter daCustomer = new customerTableAdapter(); try { daCustomer.Update(dsCustomer.customer); dsCustomer.AcceptChanges(); this.lblStatus.Text = "Customer Created"; Clear(); } catch { dsCustomer.RejectChanges(); this.lblStatus.Text = "Failed"; } }
protected void btnDeleteConfirm_Click(object sender, EventArgs e) { if (id != -1) { try { DataRow record = dsCustomer.customer.FindByID(id); // Find and add the record to tbe record variable record.Delete(); // Deletes the record in memory customerTableAdapter daCustomer = new customerTableAdapter(); // table adapter to service table (Service adapter) daCustomer.Update(record); // Call update method on the service adapter so it updates the table in memory ( All changes made are applied - CRUD) dsCustomer.AcceptChanges(); // Call accept method on the dataset so it update the chanmges to the database //Refresh the page to show the record being deleted Response.Redirect("Default.aspx"); } catch { lblStatus.Text = "Delete failed. The customer has an equipment asigned."; } } }