I Have another Issue with my Code (ARGGGH!) I have a request.querys开发者_JS百科tring 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
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:
string getAccountRef = (string)Request.QueryString["AccountRef"].ToString()
Is doubly redundant. There's no need to cast the result of .ToString()
to string, as ToString()
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:
string getAccountRef = Request.QueryString["AccountRef"];
I got it! there was not a parameter set in my SQLDataSource!
<SelectParameters>
<asp:Parameter DefaultValue="1" Name="AccountRef" Type="String" />
</SelectParameters>
Thanks guy's
精彩评论