各位大神帮看看,为什么总是指定的参数已超出有效值的范围。

windspeedky 2013-06-10 10:30:02
代码如下:
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>");




}
}
...全文
233 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
windspeedky 2013-06-11
  • 打赏
  • 举报
回复

liujf 2013-06-11
  • 打赏
  • 举报
回复
你看看你数据表中有几行,这个错误已经很明确的说明是索引值越界的问题
MikeCheers 2013-06-10
  • 打赏
  • 举报
回复
这几段代码都有可能出现你说的问题 不知道你说的问题出在哪部分 一般这种问题的来源无非就是数组越界 设置断点跟踪一下 不难查
Mic_Gary 2013-06-10
  • 打赏
  • 举报
回复
数据库表贴出来看看,或者你自己比较一下,这个studentid怎么会等于个name去呢,很有可能是你这个name弄错了吧,不过如果你数据库就是这样设计的,那我也没话说了
moonwrite 2013-06-10
  • 打赏
  • 举报
回复
学会下断点 自己调试 看看最后拼接出来的sql 另外 我很讨厌拼接字符串 下面这种写法 可以减少拼接出错 http://blog.csdn.net/shuyizhi/article/details/6100331

111,092

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧