您的位置:首页 > 编程语言 > ASP

用asp.net编写页面,GridView控件中update存在问题,指定的参数已超出有效值的范围。 参数名: index 说明: 执行当前 Web 请求期间,出现未经处理的异常。跪求大佬

2018-06-19 12:51 1146 查看

指定的参数已超出有效值的范围。
参数名: index

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

异常详细信息: System.ArgumentOutOfRangeException: 指定的参数已超出有效值的范围。
参数名: index

源错误: 

行 50:             cm.Parameters.Add(new SqlParameter("@Student_id", SqlDbType.VarChar, 50));
行 51:             String colvalue;
行 52:             colvalue = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString();
行 53:             cm.Parameters["@Student_name"].Value = colvalue;
行 54:             colvalue = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString();

源文件: C:\Users\罗坤\Desktop\Solution1\WebApplication2\student.aspx.cs    行: 52 

堆栈跟踪: 


[ArgumentOutOfRangeException: 指定的参数已超出有效值的范围。
参数名: index]
System.Web.UI.ControlCollection.get_Item(Int32 index) +9822717
WebApplication2.student.GridView1_RowUpdating(Object sender, GridViewUpdateEventArgs e) in C:\Users\罗坤\Desktop\Solution1\WebApplication2\student.aspx.cs:52
System.Web.UI.WebControls.GridView.OnRowUpdating(GridViewUpdateEventArgs e) +122
System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32 rowIndex, Boolean causesValidation) +792
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +877
System.Web.UI.WebControls.GridView.RaisePostBackEvent(String eventArgument) +201
System.Web.UI.WebControls.GridView.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +15
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +9884558
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1639



        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            SqlCommand cm = new SqlCommand("update_student_1", cn);
            cm.CommandType = CommandType.StoredProcedure;
            cm.Parameters.Add(new SqlParameter("@Student_name", SqlDbType.VarChar, 50));
            cm.Parameters.Add(new SqlParameter("@Student_sex", SqlDbType.Char, 5));
            cm.Parameters.Add(new SqlParameter("@Student_birthday", SqlDbType.DateTime, 8));
            cm.Parameters.Add(new SqlParameter("@Student_id", SqlDbType.VarChar, 50));
            String colvalue;
            colvalue = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString();
            cm.Parameters["@Student_name"].Value = colvalue;
            colvalue = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString();
            cm.Parameters["@Student_sex"].Value = colvalue;
            colvalue = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString();
            cm.Parameters["@Student_birthday"].Value = colvalue;
            cm.Parameters["@Student_id"].Value = GridView1.DataKeys[e.RowIndex].Value.ToString();
            cm.Connection.Open();
            try
            {
                cm.ExecuteNonQuery();
                Lbl_note.Text = "编辑成功";
                GridView1.EditIndex = -1;
            }
            catch (SqlException)
            {
                Lbl_note.Text = "编辑失败,请检查输入!";
                Lbl_note.Style["color"] = "red";
            }
            cm.Connection.Close();
            Bindgrid();
        }

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐