日期:2014-05-17  浏览次数:20479 次

求大神帮忙呀
错误时这么说的:当传递具有新行的 DataRow 集合时,更新要求有效的 InsertCommand。


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class Masters_AdminBlue_Demo_Add : System.Web.UI.Page
{
  private int CateId;

  protected void Page_Load(object sender, EventArgs e)
  {
  if (Request.QueryString["CateId"] != null)
  {
  CateId = Convert.ToInt32(Request.QueryString["CateId"].ToString());


  }
  }

  protected void Button1_Click1(object sender, EventArgs e)
  {
  COOL.NEWSTableAdapters.CMS_ContentTableAdapter adp = new COOL.NEWSTableAdapters.CMS_ContentTableAdapter();
  COOL.NEWS.CMS_ContentDataTable dt = new COOL.NEWS.CMS_ContentDataTable();
  COOL.NEWS.CMS_ContentRow dr =dt.NewCMS_ContentRow();

  dr.CateID = CateId; 
  dr.CMS_Cnt =Convert.ToString(FCKeditor1.Value);
  dr.CMS_Title =Convert.ToString(tbOld.Text) ;


  dt.AddCMS_ContentRow(dr);

  if (adp.Update(dt) > 0)
  {
  Tool.Message.ClientMsgPrompt(this, "添加成功");
  tbOld.Text = "";
  FCKeditor1.Value = "";
  }

  else
  Tool.Message.ClientMsgPrompt(this, "添加失败");
  }

  protected void Button2_Click(object sender, EventArgs e)
  {
  Response.Redirect(string.Format("Add.aspx?CateId={0}", CateId));
  }
}

------解决方案--------------------
是什么问题呢?页面跳转,参数没有传递过去?还是???
如果是参数没有传递过去,这样
C# code

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class Masters_AdminBlue_Demo_Add : System.Web.UI.Page
{
  private int CateId;

 protected void Page_Load(object sender, EventArgs e)
{
     if(!IsPostBack)
     {
         if (Request.QueryString["CateId"] != null)
         {
               CateId = Convert.ToInt32(Request.QueryString["CateId"].ToString());
               ViewState["cateID"]  = Convert.ToInt32(Request.QueryString["CateId"].ToString());
         }
      }
  }

protected void Button1_Click1(object sender, EventArgs e)
{
  COOL.NEWSTableAdapters.CMS_ContentTableAdapter adp = new COOL.NEWSTableAdapters.CMS_ContentTableAdapter();
  COOL.NEWS.CMS_ContentDataTable dt = new COOL.NEWS.CMS_ContentDataTable();
  COOL.NEWS.CMS_ContentRow dr =dt.NewCMS_ContentRow();

  dr.CateID = int.Parse(ViewState["cateID"].ToString()); 
  dr.CMS_Cnt =Convert.ToString(FCKeditor1.Value);
  dr.CMS_Title =Convert.ToString(tbOld.Text) ;


  dt.AddCMS_ContentRow(dr);

  if (adp.Update(dt) > 0)
  {
       Tool.Message.ClientMsgPrompt(this, "添加成功");
       tbOld.Text = "";
       FCKeditor1.Value = "";
   }
  else
   {
      Tool.Message.ClientMsgPrompt(this, "添加失败");
    }
}

   protected void Button2_Click(object sender, EventArgs e)
   {
        Response.Redirect(string.Format("Add.aspx?CateId={0}",  int.Parse(ViewState["cateID"].ToString())));
   }
}

------解决方案--------------------