Пример #1
0
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            id = Convert.ToInt32(Request.QueryString["ID"]);
            DataRow record = dsInventory.Inventory.FindByid(id);

            // Find the related Record and fill the fields in the page with the data


            try
            {
                record[1] = txtQuantity.Text;
                record[2] = txtSize.Text;
                record[5] = ddlProducts.SelectedValue;
                record[3] = ddlMeasures.SelectedValue;
                record[4] = txtPrice.Text;

                daInventory.Update(record);
                // Call update method on the service adapter so it updates the table in memory ( All changes made are applied - CRUD)
                dsInventory.AcceptChanges();
                Response.Redirect("Default.aspx");
            }
            catch (Exception ex)
            {
                lblMessage.Text    = "Failed to update";
                lblMessage.Visible = true;
            }
        }
Пример #2
0
        protected void btnAddItem_Click(object sender, EventArgs e)
        {
            try
            {
                DataRow Inventorydata = dsInventory.Product.NewRow(); // Create a new row of service_order table in memory
                                                                      //update record with user's input

                Inventorydata[1] = this.txtProduct.Text;
                Inventorydata[3] = this.ddlBrand.SelectedValue;

                Inventorydata[2] = this.txtDescription.Text;


                ProductTableAdapter ProductTable = new ProductTableAdapter();
                dsInventory.Product.Rows.Add(Inventorydata); // add the rows to the dataset


                ProductTable.Update(Inventorydata);
                // Call update method on the service adapter so it updates the table in memory ( All changes made are applied - CRUD)
                dsInventory.AcceptChanges();
                // Call accept method on the dataset so it update the chanmges to the database
                lblMessage.Text = "Created 1";

                //Refresh the page to show the record being deleted
                Response.Redirect("Default.aspx"); // Redirect the user to dexpage on to show created data

                lblMessage.Text = "Created";
            }
            catch
            {
                lblMessage.Text = "Failed";
            }
        }
Пример #3
0
        protected void btnDeleteConfirm_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(Request.QueryString["ID"]);

            try
            {
                DataRow record = dsInventory.Inventory.FindByid(id); // Find the requested record
                record.Delete();                                     // Deletes the record in memory\
                daInventory.Update(record);                          // Call update method on the Repair adapter so it updates the table in memory ( All changes made are applied - CRUD)
                dsInventory.AcceptChanges();                         // Call accept method on the dataset so it update the chanmges to the database
                Response.Redirect("/Inventory");
            }
            catch (Exception ex)
            {
                lblMessage.Text = "Failed: " + ex.Message;
            }
        }