public static int UpdateCategory(Category category)
        {
            string sql = "update category set categoryName=@categoryName,categoryDescription=@categoryDescription,categoryImage=@categoryImage,departId=@departId,[order]=@order,active=@active,parentcat=@parentcat,categoryShortName=@categoryShortName where categoryId=@categoryId";
            SqlParameter[] para = new SqlParameter[] 
           {
               new SqlParameter("@categoryName",category.CategoryName),
               new SqlParameter("@categoryDescription",category.CategoryDescription),
               new SqlParameter("@categoryImage",category.CategoryImage),
               new SqlParameter("@departId",category.DepartId.DepartId),
               new SqlParameter("@order",category.Order),
               new SqlParameter("@active",category.Active==true?1:0),
               new SqlParameter("@parentcat",category.Parentcat),
               new SqlParameter("@categoryShortName",category.CategoryShortName),
               new SqlParameter("@categoryId",category.CategoryId)
           };
            int count = DBHelpers.ExecuteCommand(sql, para);
            return count;
        }// 下面这个是没有问题的 其他修改也用到这个方法 没有问题 
    public static int ExecuteCommand(string sql, params SqlParameter[] values)
        {
            SqlCommand cmd = new SqlCommand(sql, Connection);
            SqlTransaction trans = connection.BeginTransaction();
            try
            {
                cmd.Transaction = trans;
                cmd.Parameters.AddRange(values);
                int result = cmd.ExecuteNonQuery();
                trans.Commit();
                return result;
            }
            catch (System.Data.SqlClient.SqlException e)
            {
                trans.Rollback();
                throw new Exception(e.Message);
            }        }

解决方案 »

  1.   

    The parameterized query '(@name nvarchar(13),@price decimal(4,2),@categoryId int,@images ' expects the parameter '@checkoutname', which was not supplied. 
    Stack Trace: 
    [Exception: The parameterized query '(@name nvarchar(13),@price decimal(4,2),@categoryId int,@images ' expects the parameter '@checkoutname', which was not supplied.]
       czechandspeakeDAL.DBHelpers.ExecuteCommand(String sql, SqlParameter[] values) in E:\CMS\prototype\czechandspeakeWeb.root\czechandspeakeWeb\czechandspeakeDAL\DBHelpers.cs:72
       czechandspeakeDAL.ProductServices.UpdateProductInfo(Products pro) in E:\CMS\prototype\czechandspeakeWeb.root\czechandspeakeWeb\czechandspeakeDAL\ProductServices.cs:316
       czechandspeakeBLL.productManager.UpdateProductInfo(Products pro) in E:\CMS\prototype\czechandspeakeWeb.root\czechandspeakeWeb\czechandspeakeBLL\productManager.cs:67
       Member_Maintenance.dgvProductList_RowCommand(Object sender, GridViewCommandEventArgs e) in e:\CMS\prototype\czechandspeakeWeb.root\czechandspeakeWeb\czechandspeakeWeb\Member\Maintenance.aspx.cs:209
       System.Web.UI.WebControls.GridView.OnRowCommand(GridViewCommandEventArgs e) +126
       System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +187
       System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) +173
       System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +70
       System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +136
       System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +70
       System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +140
       System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +206
       System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +39
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +37
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +286
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4157 这个是报的错误。
      

  2.   

    不是上面的那个update方法 是这个。。
    public static int UpdateProductInfo(Products pro)
            {
                string sql = "update ProductInfo set productName=@name,productPrice=@price,categoryId=@categoryId,productImage=@images,productVolume=@volume,productCode=@code,active=@active,productVat=@vat,checkoutName=@checkoutname,[weight]=@weight,preorder=@preorder,outofstock=@outofstock,[order]=@order,categoryId2=@catId2 where productId=@productId";
                SqlParameter[] para = new SqlParameter[] 
               {
                    new SqlParameter("@name",pro.ProductName), 
                    new SqlParameter("@price",pro.ProductPrice), 
                    new SqlParameter("@categoryId",pro.CategoryId.CategoryId), 
                    new SqlParameter("@images",pro.ProductImage),
                    new SqlParameter("@volume",pro.ProductVolume),
                   new SqlParameter("@code",pro.ProductCode),
                   new SqlParameter("@active",pro.Active==true?1:0),
                   new SqlParameter("@vat",pro.ProductVat),
                   new SqlParameter("@checkoutname",pro.ProductCheckName),
                   new SqlParameter("@weight",pro.Weight),
                   new SqlParameter("@preorder",pro.PreOrder),
                   new SqlParameter("@outofstock",pro.OutOfStock),
                   new SqlParameter("@order",pro.Order),
                   new SqlParameter("@catId2",pro.CategoryId2),
                   new SqlParameter("@productId",pro.ProductId)
                };
                int count = DBHelpers.ExecuteCommand(sql, para);
                return count;
            }这个报错!!! 不是1楼那个。
      

  3.   

    是2楼的这个update方法报错  不是我第一次发的那个update方法。大家帮忙看看。谢谢
      

  4.   

    你跟踪调试一下,看你的pro.ProductName等这些属性都有值没有。如果值为null,肯定是会报错的。。
      

  5.   

    而且这个dbhelper类里面还用事务,有必要吗?一个单独的修改语句,用事务干啥?public static int ExecuteCommand(string sql, params SqlParameter[] values)
      {
      SqlCommand cmd = new SqlCommand(sql, Connection);
      SqlTransaction trans = connection.BeginTransaction();//可以去掉
      try
      {
      cmd.Transaction = trans;//可以去掉
      cmd.Parameters.AddRange(values);
      int result = cmd.ExecuteNonQuery();
      trans.Commit();//可以去掉
      return result;
      }
      catch (System.Data.SqlClient.SqlException e)
      {
      trans.Rollback();//可以去掉
      throw new Exception(e.Message);
      }  }
      

  6.   

    其他方法的修改用这个ExecuteCommand(sql,para)都可以的
      

  7.   


    谢谢你。就是有一个为null,呵呵!自己太粗心了、