System.ArgumentOutOfRangeException:索引超出范围
我的代码还有另一个问题(ARGGGH!)我正在调用 request.querystring,但收到以下错误 索引超出范围。必须为非负数且小于集合的大小。参数名称:index
public void getAccountRef()
{
string getAccountRef = (string)Request.QueryString["AccountRef"].ToString();
SqlDataSource1.SelectParameters[0].DefaultValue = getAccountRef;
}
有什么想法吗?我正在尝试解析帐户引用,其格式类似于 REDIT1
Cheers
Justin
I Have another Issue with my Code (ARGGGH!) I have a request.querystring that I am calling and i get the following error Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
public void getAccountRef()
{
string getAccountRef = (string)Request.QueryString["AccountRef"].ToString();
SqlDataSource1.SelectParameters[0].DefaultValue = getAccountRef;
}
Any thoughts why? I am trying to parse the account ref which is going to formatted like REDIT1
Cheers
Justin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我敢打赌 SqlDataSource1 没有设置参数,因此您尝试访问第一个(项目 0)会失败,因为索引必须在 0 到 Count-1 的范围内(在本例中没有任何内容满足)。您需要添加该参数。
另请注意:
是双重冗余的。无需将
.ToString()
的结果转换为字符串,因为ToString()
始终返回字符串。也无需对
Request.Querystring[fieldName]
的结果调用它,因为它也始终返回一个字符串。以下内容就足够了:I'd bet that SqlDataSource1 had no parameters set, so your attempt to access the first (item 0) fails as the index must be in the range from 0 to Count-1 (which nothing satisfies in this case). You need to add the parameter.
Also note that:
Is doubly redundant. There's no need to cast the result of
.ToString()
to string, asToString()
always returns a string.There's also no need to call it on the result of
Request.Querystring[fieldName]
as that also always returns a string. The following would suffice:我得到了它!我的 SQLDataSource 中没有设置参数!
谢谢那家伙的
I got it! there was not a parameter set in my SQLDataSource!
Thanks guy's