各位大神帮看看,为什么总是指定的参数已超出有效值的范围。
代码如下:using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Configuration;
public partial class Main : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
using (OleDbConnection olecon = new OleDbConnection(ConfigurationManager.ConnectionStrings["conn"].ToString()))
{
string name = Session["name"].ToString();
{
try
{
olecon.Open();
OleDbCommand oledbcommand = new OleDbCommand("select * from StudentInfo where StudentId='" + name + "'", olecon);
OleDbDataReader da = oledbcommand.ExecuteReader();
this.GridView1.DataSource = da;
this.GridView1.DataKeyNames = new string[] { "StudentId" };
this.GridView1.DataBind();
da.Close();
}
catch (Exception)
{
throw;
}
}
}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string A = GridView1.DataKeys[e.RowIndex].Value.ToString();
string B = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim();
string C = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim();
string D = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim();
string E = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim();
string F = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim();
string G = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[6].Controls[0])).Text.ToString().Trim();
string H = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[7].Controls[0])).Text.ToString().Trim();
string s = "update StudentId='" + A + "',StudentName='" + B + "',Sex='" + C + "',DateOfBirth='" + D + "',Specialty='" + E + "',Email='" + F + "',Root='" + G + ",PassWord='" + H + "'";
Response.Write("<script language=javascript> alert('数据更新成功!');window.location='ManagerNews.aspx'</script>");
}
} GridView --------------------编程问答-------------------- 学会下断点 自己调试 看看最后拼接出来的sql
另外 我很讨厌拼接字符串
下面这种写法 可以减少拼接出错
http://blog.csdn.net/shuyizhi/article/details/6100331 --------------------编程问答-------------------- 数据库表贴出来看看,或者你自己比较一下,这个studentid怎么会等于个name去呢,很有可能是你这个name弄错了吧,不过如果你数据库就是这样设计的,那我也没话说了 --------------------编程问答-------------------- 这几段代码都有可能出现你说的问题
不知道你说的问题出在哪部分
一般这种问题的来源无非就是数组越界
设置断点跟踪一下
不难查 --------------------编程问答--------------------
--------------------编程问答-------------------- 你看看你数据表中有几行,这个错误已经很明确的说明是索引值越界的问题
补充:.NET技术 , C#