索引超出范围。必须为非负值并小于集合大小。 参数名: index public partial class
说明:执行当前Web请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。异常详细信息:System.ArgumentOut...
说明: 执行当前 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();
}
} 展开
异常详细信息: 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();
}
} 展开
2个回答
展开全部
错误都告诉你了,在33行出的错:
行 33: SqlCommand mycom = new SqlCommand("delete from gridview where id='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'",mycon);
也就是DataKeys[e.RowIndex]出错了,
要么e.RowIndex为-1,要么e.RowIndex超过DataKeys的长度了
行 33: SqlCommand mycom = new SqlCommand("delete from gridview where id='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'",mycon);
也就是DataKeys[e.RowIndex]出错了,
要么e.RowIndex为-1,要么e.RowIndex超过DataKeys的长度了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
TableDI
2024-07-18 广告
2024-07-18 广告
在Excel中,使用`VLOOKUP`函数进行单一条件查找非常常见,但`VLOOKUP`本身并不直接支持双重条件。然而,你可以通过一些间接方法实现。一种方法是将两个条件合并为一个标识符(例如,通过连接或串联),然后在另一个区域中查找此标识符...
点击进入详情页
本回答由TableDI提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询