早教吧作业答案频道 -->其他-->
索引超出范围。必须为非负值并小于集合大小。参数名: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 调试吧 看代码是看不出来的。。。
看了索引超出范围。必须为非负值并小...的网友还看了以下:
概率论与数理统计题目:设随机变量X~N(u,σ^2),求E|x-u|^k 2020-04-05 …
1.下列对欧姆定律表达式I=U/R的理解中正确的是A.U与R的比值是一个恒量B.导体的电阻一定时, 2020-04-08 …
经观测,某公路段在某时段内的车流量y(千辆/小时)与汽车的平均速度u(千米/小时)之间有函数关系y 2020-05-17 …
数理统计当中,什么叫做单正态总体?设总体的均值为u,方差为σ^2,X1,X2,……Xn是取自X的一 2020-06-10 …
数理统计学,总体均值估计中,大样本方法时U是什么书上说因为平均数近似服从正态分布N(μ,σ²/n) 2020-06-10 …
下列词语中,加点的字读音全部都正确的一组是()A.牛虻(ménɡ)氓隶(ménɡ)魍魉(wǎnɡ) 2020-07-03 …
高中生数学计算类的题经常出错怎么办?我是一名将要上高二的学生,物理上经常在一些计算题上出错,解题时 2020-07-18 …
Uxx+2Uxy-3Uyy=0,x属于R,y>0,U(x,0)=3X^2,Uy(x,0)=0求解U( 2020-11-01 …
奇数效用与序数效用区别在哪奇数效用与序数效用均衡条件一致,就序数效用的无差异曲线所表现的U函数,在X 2020-11-17 …
中数在去掉两个极端值后会不会受影响1、做题看到的,去掉两个极端值后一定不会受影响的是答案是众数2、标 2020-11-18 …