//指定的参数已超出有效值的范围。参数名: index

dingzheng1989 2010-10-24 10:37:30
给GridView1写了一个Bind()函数,但是catch到异常如题,大侠们帮帮,实在不知道怎么解决,谢谢了

Bing()内代码如下:


string strValue = 8;
string strComm = "SELECT stu_Img, tbStu_infor.stu_NO, tbStu_infor.stu_Name, tbStu_infor.stu_Sex, tbStu_infor.stu_ID, tbStu_infor.stu_Age, tbStu_infor.stu_HomeAddr, tbStu_infor.stu_Tel, tbStu_infor.stu_Polit, tbStu_infor.stu_Other, tbClass_infor.Grade + tbClass_infor.class_Name + tbClass_infor.class_ID AS CLASS, tbClass_infor.class_LenOfSch FROM tbStu_infor INNER JOIN tbClass_infor ON tbStu_infor.stu_ClassNO = tbClass_infor.class_NO where tbClass_infor.class_NO=\'"+strValue+"\'";
using (SqlConnection conn = new SqlConnection(CommonMethods.connString))
{
SqlDataAdapter adapter = new SqlDataAdapter(strComm, conn);
DataSet dataSet = new DataSet();
try
{
adapter.Fill(dataSet, "tbStu_infor");
GridView1.DataSource = dataSet;
GridView1.DataKeyNames = new string[] { "stu_NO" };//主键
GridView1.DataBind();//指定的参数已超出有效值的范围。参数名: index
}
catch
{
//指定的参数已超出有效值的范围。参数名: index
//DO SOMETHING
}
finally
{
conn.Close();
dataSet.Dispose();
}
}
...全文
416 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
dingzheng1989 2010-10-24
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 wuyq11 的回复:]
找到就好
[/Quote]
网速卡 ,我结贴给分的,不知怎么出的什么错,结子结了,分好像没给上,不好意思
dingzheng1989 2010-10-24
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wuyq11 的回复:]
...tbClass_infor.class_NO='"+strValue+"'";
检查GridView1页面的绑定
超出索引范围
还有rowdatabound里是否有相关处理
[/Quote]
谢谢你,是rowdatabound里有问题了,你已经回答过我好多问题了,
Thanks Very Much.

向人生如梦看齐
dingzheng1989 2010-10-24
  • 打赏
  • 举报
回复

堆栈跟踪:


[ArgumentOutOfRangeException: 指定的参数已超出有效值的范围。
参数名: index]
System.Web.UI.ControlCollection.get_Item(Int32 index) +8673806
Pages_StuArchives_StuPersonInfort.GridView1_RowDataBound(Object sender, GridViewRowEventArgs e) in c:\Users\DING\Desktop\web更新\Pages\StuArchives\StuPersonInfor.aspx.cs:112
System.Web.UI.WebControls.GridView.OnRowDataBound(GridViewRowEventArgs e) +108
System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource) +167
System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +2417
System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +57
System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) +14
System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
System.Web.UI.WebControls.GridView.DataBind() +4
Pages_StuArchives_StuPersonInfort.bind() in c:\Users\DING\Desktop\web更新\Pages\StuArchives\StuPersonInfor.aspx.cs:83
Pages_StuArchives_StuPersonInfort.Page_Load(Object sender, EventArgs e) in c:\Users\DING\Desktop\web更新\Pages\StuArchives\StuPersonInfor.aspx.cs:53
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627


大侠们帮下,这个代码在别的表里也用过没问题,怎么到这里就有问题了呢?
谢谢了.
wuyq11 2010-10-24
  • 打赏
  • 举报
回复
...tbClass_infor.class_NO='"+strValue+"'";
检查GridView1页面的绑定
超出索引范围
还有rowdatabound里是否有相关处理

62,244

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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