using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class BackgroundManagement_MedicineProductEdit : System.Web.UI.Page
{
    #region Editing-Related Event Handlers
    protected void DataList1_EditCommand(object source, DataListCommandEventArgs e)
    {
        // Set the DataList's EditItemIndex property to the
        // index of the DataListItem that was clicked
        DataList1.EditItemIndex = e.Item.ItemIndex;        // Rebind the data to the DataList
        DataList1.DataBind();
    }    protected void DataList1_CancelCommand(object source, DataListCommandEventArgs e)
    {
        // Set the DataList's EditItemIndex property to -1
        DataList1.EditItemIndex = -1;        // Rebind the data to the DataList
        DataList1.DataBind();
    }    protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e)
    {
        // Read in the ProductID from the DataKeys collection
        int productID = Convert.ToInt32(DataList1.DataKeys[e.Item.ItemIndex]);        // Read in the product name and price values
        TextBox productName = (TextBox)e.Item.FindControl("ProductName");
        TextBox quantityPerUnit = (TextBox)e.Item.FindControl("QuantityPerUnit");
        TextBox unitPrice = (TextBox)e.Item.FindControl("UnitPrice");
        TextBox description = (TextBox)e.Item.FindControl("Description");        string productNameValue = null;
        if (productName.Text.Trim().Length > 0)
            productNameValue = productName.Text.Trim();        string quantityPerUnitValue = null;
        if (quantityPerUnit.Text.Trim().Length > 0)
            quantityPerUnitValue = quantityPerUnit.Text.Trim();        string unitPriceValue = null;
        if (unitPrice.Text.Trim().Length > 0)
            unitPriceValue = unitPrice.Text.Trim();        string descriptionValue = null;
        if (description.Text.Trim().Length > 0)
            descriptionValue = description.Text.Trim();        // Call the ProductsBLL's UpdateProduct method...
        MedicineProductsBLL productsAPI = new MedicineProductsBLL();
        productsAPI.UpdateMedicineProduct(productNameValue,quantityPerUnitValue, unitPriceValue,descriptionValue, productID);
        // Revert the DataList back to its pre-editing state
        DataList1.EditItemIndex = -1;
        DataList1.DataBind();
    }
    #endregion    protected void DataList1_DeleteCommand(object source, DataListCommandEventArgs e)
    {
        // Read in the ProductID from the DataKeys collection
        int productID = Convert.ToInt32(DataList1.DataKeys[e.Item.ItemIndex]);        // Delete the data
        MedicineProductsBLL productsAPI = new MedicineProductsBLL();
        productsAPI.DeleteMedicineProduct(productID);        // Rebind the data to the DataList
        DataList1.DataBind();
    }
}

解决方案 »

  1.   

    UpdateMedicineProduct函数的参数个数根本就没有5个..你应该检查这个方法
      

  2.   

    这个是MedicineProductBLL的代码,大家帮忙看看
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using NorthwindTableAdapters;[System.ComponentModel.DataObject]
    public class MedicineProductsBLL
    {
        private MedicineProductsTableAdapter _medicineProductsAdapter = null;
        protected MedicineProductsTableAdapter Adapter
        {
            get
            {
                if (_medicineProductsAdapter == null)
                    _medicineProductsAdapter = new MedicineProductsTableAdapter();            return _medicineProductsAdapter;
            }
        }    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public Northwind.MedicineProductsDataTable GetMedicineProducts()
        {
            return Adapter.GetMedicineProducts();
        }    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
        public Northwind.MedicineProductsDataTable GetMedicineProductByProductID(int productID)
        {
            return Adapter.GetMedicineProductByProductID(productID);
        }    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
        public Northwind.MedicineProductsDataTable GetMedicineProductsByCategoryID(int categoryID)
        {
            return Adapter.GetMedicineProductsByCategoryID(categoryID);
        }    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, true)]
        public bool AddMedicineProduct(string productName, int? categoryID, string quantityPerUnit,
                              string unitPrice, string imageName, string imageType, string imagePath,string description,
                              DateTime postTime)
        {
            // Create a new ProductRow instance
            Northwind.MedicineProductsDataTable products = new Northwind.MedicineProductsDataTable();
            Northwind.MedicineProductsRow product = products.NewMedicineProductsRow();        product.ProductName = productName;
            if (categoryID == null) product.SetCategoryIDNull(); else product.CategoryID = categoryID.Value;
            if (quantityPerUnit == null) product.SetQuantityPerUnitNull(); else product.QuantityPerUnit = quantityPerUnit;
            if (unitPrice == null) product.SetUnitPriceNull(); else product.UnitPrice = unitPrice;
            if (imageName == null) product.SetImageNameNull(); else product.ImageName = imageName;
            if (imageType == null) product.SetImageTypeNull(); else product.ImageType = imageType;
            if (imagePath == null) product.SetImagePathNull(); else product.ImagePath = imagePath;
            if (description == null) product.SetDescriptionNull(); else product.Description = description;
            product.PostTime = postTime;
            // Add the new product
            products.AddMedicineProductsRow(product);
            int rowsAffected = Adapter.Update(products);        // Return true if precisely one row was inserted, otherwise false
            return rowsAffected == 1;
        }    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
        public bool UpdateMedicineProduct(string productName, int? categoryID, string quantityPerUnit,
                              string unitPrice, string imageName, string imageType, string imagePath,string description,
                              DateTime postTime, int productID)
        {
            Northwind.MedicineProductsDataTable products = Adapter.GetMedicineProductByProductID(productID);
            if (products.Count == 0)
                // no matching record found, return false
                return false;        Northwind.MedicineProductsRow product = products[0];        // Business rule check - cannot discontinue a product that's supplied by only
            // one supplier
            product.ProductName = productName;
            if (categoryID == null) product.SetCategoryIDNull(); else product.CategoryID = categoryID.Value;
            if (quantityPerUnit == null) product.SetQuantityPerUnitNull(); else product.QuantityPerUnit = quantityPerUnit;
            if (unitPrice == null) product.SetUnitPriceNull(); else product.UnitPrice = unitPrice;
            if (imageName == null) product.SetImageNameNull(); else product.ImageName = imageName;
            if (imageType == null) product.SetImageTypeNull(); else product.ImageType = imageType;
            if (imagePath == null) product.SetImagePathNull(); else product.ImagePath = imagePath;
            if (description == null) product.SetDescriptionNull(); else product.Description = description;
            product.PostTime = postTime;        // Update the product record
            int rowsAffected = Adapter.Update(product);        // Return true if precisely one row was updated, otherwise false
            return rowsAffected == 1;
        }    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Delete, true)]
        public bool DeleteMedicineProduct(int productID)
        {
            int rowsAffected = Adapter.Delete(productID);        // Return true if precisely one row was deleted, otherwise false
            return rowsAffected == 1;
        }
    }