当前位置:编程学习 > C#/ASP.NET >>

更新已有内容时提示 对象必须实现 IConvertible

说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 

异常详细信息: System.InvalidCastException: 对象必须实现 IConvertible。

源错误: 

执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。  

堆栈跟踪: 


[InvalidCastException: 对象必须实现 IConvertible。]
   System.Convert.ChangeType(Object value, TypeCode typeCode, IFormatProvider provider) +2563250
   System.Web.UI.WebControls.Parameter.GetValue(Object value, String defaultValue, TypeCode type, Boolean convertEmptyStringToNull, Boolean ignoreNullableTypeChanges) +248
   System.Web.UI.WebControls.SqlDataSourceView.AddParameters(DbCommand command, ParameterCollection reference, IDictionary parameters, IDictionary exclusionList, String oldValuesParameterFormatString) +547
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +411
   System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +78
   System.Web.UI.WebControls.FormView.HandleUpdate(String commandArg, Boolean causesValidation) +1150
   System.Web.UI.WebControls.FormView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +450
   System.Web.UI.WebControls.FormView.OnBubbleEvent(Object source, EventArgs e) +88
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
   System.Web.UI.WebControls.FormViewRow.OnBubbleEvent(Object source, EventArgs e) +109
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
   System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +86
   System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +155
   System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +170
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4919

 
--------------------编程问答-------------------- 这个应该是数据类型转换的问题了。看看你更改的时候的语句中的值是不是没有做处理。没有提示具体的错误行和错误代码吗? --------------------编程问答-------------------- 没有具体的。我在写入新内容的时候所用的数据处理方法是一样的啊,能写入,但不能更改。 --------------------编程问答--------------------  protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ((DropDownList)this.FormView1.FindControl("DropDownList1")).Items.Clear();
            ((DropDownList)this.FormView1.FindControl("DropDownList6")).Items.Clear();

            int k = 0;
            for (k = 0; k < 24; k++)
            {
                ((DropDownList)this.FormView1.FindControl("DropDownList1")).Items.Add(k.ToString());
                ((DropDownList)this.FormView1.FindControl("DropDownList6")).Items.Add(k.ToString());
            }
            ((DropDownList)this.FormView1.FindControl("DropDownList2")).Items.Clear();
            ((DropDownList)this.FormView1.FindControl("DropDownList7")).Items.Clear();

            int r = 0;
            for (r = 0; r < 60; r++)
            {
                ((DropDownList)this.FormView1.FindControl("DropDownList2")).Items.Add(r.ToString());
                ((DropDownList)this.FormView1.FindControl("DropDownList7")).Items.Add(r.ToString());
            }

            ((LinkButton)this.FormView1.FindControl("InsertButton")).Attributes.Add("onclick", "javascript:if(confirm('确定要添加吗?')){}else{return false;}");
        }
    }
    protected void InsertButton_Click(object sender, EventArgs e)
    {
        //插入日期
        ((HiddenField)this.FormView1.FindControl("HiddenField1")).Value = ((Meta.Web.Controls.DropDownCalendar)this.FormView1.FindControl("FreeDate")).Value.ToString("d");
        //插入录入人员
        ((HiddenField)this.FormView1.FindControl("SerPerson")).Value = Session["StaffName"].ToString();
        // 插入录入时间;
        ((HiddenField)this.FormView1.FindControl("SerDate")).Value = DateTime.Now.ToString();
        //插入各起止时间
        ((HiddenField)this.FormView1.FindControl("FreeTime")).Value = (((DropDownList)this.FormView1.FindControl("DropDownList1")).Text) + ":" + (((DropDownList)this.FormView1.FindControl("DropDownList2")).Text);
        ((HiddenField)this.FormView1.FindControl("OutTime")).Value = (((DropDownList)this.FormView1.FindControl("DropDownList6")).Text) + ":" + (((DropDownList)this.FormView1.FindControl("DropDownList7")).Text);
    }
这些就是编辑页面的代码。麻烦看一下有没有错误! --------------------编程问答-------------------- 对protected void InsertButton_Click(object sender, EventArgs e) 
里面的代码中设置断点,看看执行到哪里就会出现问题。用个try  catch 来捕获该异常。
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,