早教吧作业答案频道 -->其他-->
索引超出范围。必须为非负值并小于集合大小。参数名:indexpublicpartialclass说明:执行当前Web请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误
题目详情
索引超出范围。必须为非负值并小于集合大小。 参数名: index public partial class说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.ArgumentOutOfRangeException: 索引超出范围。必须为非负值并小于集合大小。 参数名: index 源错误: 行31: { 行32: SqlConnection mycon = new SqlConnection("server=ALEXANDER-PC;uid=sa;pwd=123456;database=test"); 行33: SqlCommand mycom = new SqlCommand("delete from gridview where id='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'",mycon); 行34: mycon.Open(); 行35: mycom.ExecuteNonQuery(); 源文件: d:\WebSites\gridview\Default.aspx.cs 行: 33 堆栈跟踪: [ArgumentOutOfRangeException: 索引超出范围。必须为非负值并小于集合大小。 参数名: index] System.Collections.ArrayList.get_Item(Int32 index) +7488568 System.Web.UI.WebControls.DataKeyArray.get_Item(Int32 index) +12 _Default.GridView1_RowDeleting(Object sender, GridViewDeleteEventArgs e) in d:\WebSites\gridview\Default.aspx.cs:33 System.Web.UI.WebControls.GridView.OnRowDeleting(GridViewDeleteEventArgs e) +133 System.Web.UI.WebControls.GridView.HandleDelete(GridViewRow row, Int32 rowIndex) +569 System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +869 System.Web.UI.WebControls.GridView.RaisePostBackEvent(String eventArgument) +207 System.Web.UI.WebControls.GridView.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) +175 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565 版本信息: Microsoft .NET Framework 版本:2.0.50727.5466; ASP.NET 版本:2.0.50727.5456 public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { SqlConnection mycon = new SqlConnection("server=ALEXANDER-PC;uid=sa;pwd=123456;database=test"); SqlDataAdapter myada=new SqlDataAdapter("select*from gridview",mycon); DataSet ds = new DataSet(); myada.Fill(ds, "c"); GridView1.DataSource = ds.Tables["c"]; GridView1.DataBind(); } protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { GridView1.EditIndex = e.NewEditIndex; GridView1.DataBind(); } protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { SqlConnection mycon = new SqlConnection("server=ALEXANDER-PC;uid=sa;pwd=123456;database=test"); SqlCommand mycom = new SqlCommand("delete from gridview where id='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'",mycon); mycon.Open(); mycom.ExecuteNonQuery(); mycon.Close(); GridView1.DataBind(); } }
▼优质解答
答案和解析
索引越界 打断点在 d:\WebSites\gridview\Default.aspx.cs 行: 33 调试吧 看代码是看不出来的。。。
看了索引超出范围。必须为非负值并小...的网友还看了以下:
写出下列算法的功能LinkListdemo(LinkListL){ListNode*q,*p;If 2020-05-17 …
已知命题p:l属于{1,2},q:{l}属于{1,2},则①"p且q"为假②“p或q”为真③“非p 2020-06-04 …
命题p错误,非p一定正确?命题的非p和否命题一样吗?请详解.P命题:如果x大于2,那么X大于3他的 2020-06-07 …
数学命题P错误,非P一定正确么,就是P和非P一定是一个正确一个错误么不对的话有反例么 2020-06-07 …
数据结构问题,不懂啊,兄弟已知L是带表头结点的非空单链表,且P结点既不是首元结点,也不是尾元结点, 2020-07-14 …
离散数学主合取题(非P→Q)→(非QvP)的主合取范式答案上给出的是非QvP我算出来的是非Q且P所 2020-07-14 …
逻辑推理题一个同为模态推理,反对关系,为什么A不能推出答案,B就可以?请说明A:“并非必然p,所以, 2020-11-28 …
C++解决一个程序1随机产生一个n*m矩阵输入m,n,L,U,p(p在(0,1]之间)2对矩阵中每一 2020-12-07 …
已知P:2+2=5,Q:3>2,则下列判断错误的是()A.“P或Q”为真,“非Q”为假B.“P且Q” 2020-12-07 …
已知P:2+2=5,Q:3>2,则下列判断错误的是()A.“P或Q”为真,“非Q”为假B.“P且Q” 2020-12-07 …