c# - System.ArgumentOutOfRangeException: Index was out of range -


I have another issue with my code (ARGGG!)! I have a request. Querystring that I'm calling and I get the following error The index was out of range was less than the non-negative and the size of the collection. Parameter Name: Index

  Public Zero getAccountRef () {string getAccountRef = (string) request .QueryString ["AccountRef"]. ToString (); SqlDataSource1.SelectParameters [0] .DefaultValue = getAccountRef; }   

Any ideas why?

Justin

I was sure that SqlDataSource1 did not have any parameter set, Therefore your effort to reach the first (item 0) fails because the index should be calculated from 0 to 0 (whatever is not satisfied in this case). You need to add the parameter

Also keep in mind that:

  string getAccountRef = (string) request. JQueryString ["AccountRef"] ToString ()   

There is no need to remove the result of double redundancy . String () string for string always gives a string.

Call it the result of Request.Querystring [fieldName] , because it always returns a string that will suffice:

  string getAccountRef = Request.QueryString ["AccountRef"];    

Comments