none
文章数据发送时 遇到异常? 这些错误 有时候遇到 , 有时候正常运行的!!!! RRS feed

  • 问题

  • protected void Button1_OnClick(object sender, System.EventArgs e)
    
     {
    
    
    
      string content = Server.HtmlEncode(WebEditor1.Text.Replace("'", "''")); 
    
      System.Text.UnicodeEncoding converter = new System.Text.UnicodeEncoding(); 
    
      byte[] byte_content = converter.GetBytes(content); 
    
    
    
    
    
      WebEditor1.Focus = true;
    
      string s_main_menu_id=menu_id(DropDownList1.Text.Trim());
    
      string s_sub_menu_id = menu_id(DropDownList2.Text.Trim());
    
      OleDbConnection con = new OleDbConnection(s_con_str);
    
      OleDbCommand com = new OleDbCommand();
    
    
    
      string s_win = "";
    
      if (s_up != null)
    
      {
    
       s_win = "update";
    
    
    
       con.Open();
    
       com = con.CreateCommand();
    
       com.CommandText = "update AL_sub_menu_content set content_title=@title , sub_menu_caption=@caption , sub_menu_content=@content, content_time=@time ,content_author=@author where content_id=@content_id";
    
       com.Parameters.AddWithValue("@title",TextBox1.Text);
    
       com.Parameters.AddWithValue("@caption",TextBox2.Text);
    
       com.Parameters.AddWithValue("@content",byte_content);
    
       com.Parameters.AddWithValue("@time",DateTime.Now.ToString());
    
       com.Parameters.AddWithValue("@author", Session["ses_user_name"].ToString());
    
       com.Parameters.AddWithValue("@content_id",Request.QueryString["update_content_id"].ToString());
    
    
    
       com.CommandType = CommandType.Text;
    
       com.ExecuteNonQuery();
    
       con.Close();
    
       ///////////////////////////////////////////////////////////////////////////////////
    
       //com.CommandText = "update [Catalog] set [CMenu] = @olevalue";
    
    
    
       //OleDbParameter olep = new OleDbParameter("@olevalue", OleDbType.LongVarBinary, buff.Length);
    
       //olep.Value = buff;
    
       //com.Parameters.Add(olep);
    
       //com.ExecuteNonQuery();
    
    
    
       Response.Redirect("win.aspx?win_name=" + s_win);
    
      }
    
      else
    
      {
    
       s_win = "send";
    
    
    
       con.Open();
    
       com = con.CreateCommand();
    
       com.CommandText = "insert into AL_sub_menu_content(content_no,content_no_name,sub_menu_id,main_id,content_title,sub_menu_caption,sub_menu_content,content_time,content_author) values(@content_no,@content_no_name,@sub_menu_id,@main_id,@content_title,@sub_menu_caption,@sub_menu_content,@content_time,@content_author)";
    
    
    
       //@content_no,@content_no_name,@sub_menu_id,@main_id,@content_title,@sub_menu_caption,@sub_menu_content,@content_time,@content_author
    
       com.Parameters.AddWithValue("@content_no", 0); //文档编号
    
       com.Parameters.AddWithValue("@content_no_name", "'يېپىق'");     //文档类别号
    
       com.Parameters.AddWithValue("@sub_menu_id", s_sub_menu_id);     //文档标题
    
       com.Parameters.AddWithValue("@main_id", s_main_menu_id);     //存储时间
    
       com.Parameters.AddWithValue("@content_title", TextBox1.Text);     //文档内容
    
       com.Parameters.AddWithValue("@sub_menu_caption", TextBox2.Text);   //经手人
    
       com.Parameters.AddWithValue("@sub_menu_content", byte_content);    //文档类型
    
       com.Parameters.AddWithValue("@content_time", DateTime.Now.ToString());     //文档类型
    
       com.Parameters.AddWithValue("@content_author", Session["ses_user_name"].ToString());     //文档类型
    
       com.CommandType = CommandType.Text;
    
       com.ExecuteNonQuery();
    
       con.Close();
    
    
    
       Response.Redirect("win.aspx?win_name=" + s_win);
    
      }
    
    
    
    
    
    
    
     }
    
    

    ////////////////////////////////////////////////////////////////////////////////////////

    这些错误 有时候遇到 , 有时候正常运行的!!!!

    ////////////////////////////////////////////////////////////////////////////////////////

    Object reference not set to an instance of an object. 
    
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
    
    
    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
    
    
    
    Source Error: 
    
    
    
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 
    
    
    
    Stack Trace: 
    
    
    
    
    
    [NullReferenceException: Object reference not set to an instance of an object.]
    
     Demo.Button1_OnClick(Object sender, EventArgs e) +679
    
     System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
    
     System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
    
     System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
    
     System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
    
     System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
    
     System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
    
    
    
     
    
    
    
    
    
    --------------------------------------------------------------------------------
    
    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1 
    
    

    spider
    2011年4月22日 12:52

答案

全部回复