急!!!!!索引超出范围。必须为非负值并小于集合大小。有具体程序,帮忙分析下,谢谢!

usingSystem;usingSystem.Configuration;usingSystem.Data;usingSystem.Linq;usingSystem.W... using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using System.Data.OleDb;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String conString = "provider = Microsoft.Ace.OLEDB.12.0 ; Data Source =" + MapPath("App_Data/数据.accdb");
OleDbConnection con = new OleDbConnection();
con.ConnectionString = conString;
OleDbCommand command = new OleDbCommand();
command.Connection = con;

String sqlString = "select * from Student_Information";
command.CommandText = sqlString;

OleDbDataAdapter dataAdapter = new OleDbDataAdapter(command);
DataTable dt = new DataTable();
dataAdapter.Fill(dt);

this.GridView1.DataSource = dt;
this.GridView1.DataBind();

}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
String conString = "provider = Microsoft.Ace.OLEDB.12.0 ; Data Source = " + MapPath("App_Data/数据.accdb");
OleDbConnection con = new OleDbConnection();
con.ConnectionString = conString;
OleDbCommand command = new OleDbCommand();
command.Connection = con;

string id = GridView1.DataKeys[e.RowIndex].Values[0].ToString();
string SqlStr = "delete from Student_Information where Student_ID=" + "'" + id + "'";
command.CommandText = SqlStr;

con.Open();
command.ExecuteNonQuery();
con.Close(); Response.Redirect("\\新建 公文包\\Default.aspx");
Response.End();

}

protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e)
{

}
}
string id = GridView1.DataKeys[e.RowIndex].Values[0].ToString();被指出如标题所示问题,应该怎么改呢?
展开
 我来答
怀古123
2009-12-24
知道答主
回答量:14
采纳率:0%
帮助的人:9.7万
展开全部
看看GridView1属性页的DataKeyNames设置了没有,如果没有,在上面写上你的主键名如:id,如果再有什么object无法识别之类的问题,把你的string id = GridView1.DataKeys[e.RowIndex].Values[0].ToString();的Values[0]的[0]去掉再看看。
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式