ArgumentOutOfRangeException was unhandled by user code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • asmx126453
    New Member
    • Sep 2008
    • 72

    ArgumentOutOfRangeException was unhandled by user code

    This is the error i Get

    Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

    It points to this code

    Code:
          if (!IsPostBack)
                {
                    localhost1.dbConnection dbConn = new localhost1.dbConnection();
                    NameValueCollection Query = Request.QueryString;
                    string[] sQuery = Query.GetValues(0);
                    string[] RefRen = Query.GetValues(1);
    This is the last error i need to solve to get my compleet application to work again but it all points to 1 webpage and i get different errors if i try different things so i dont now anymore what the best way is pleas somone help me i only need to solve this page error so my copmpleet application works

    The error points to line number 5

    But if i delete the ! before IsPostBack than it goes to this error almost the same code

    Code:
                else
                {
                    localhost1.dbConnection dbConn = new localhost1.dbConnection();
                    NameValueCollection Query = Request.QueryString;
                    string[] RefRen = Query.GetValues(1);
                    nieuw = dbConn.IsOfferteNieuw(RefRen[0].ToString());
    Also the error poitns to line number 5

    The weird thing is it only shows the error when i start debuging and that whont work but when i stop debugging the error is not is my Error List at the bottum
    Last edited by asmx126453; Nov 19 '08, 10:15 AM. Reason: Error is on rule 5 / More information
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Better check the Count property of your NameValueCollec tion before trying to access elements that are not there.

    Comment

    • asmx126453
      New Member
      • Sep 2008
      • 72

      #3
      Cud you point me in the right direction of how i can check that i lookd on the internet and tryd myself but i dont now how

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        But everything you need is there in my post. Your NameValueCollec tion is called Query. I just told you that it has a Count property which you can use to check if GetValues(n) will succeed or not. For a value n, Count must be >= n+1.

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          any time you use a blatent index on any type or array or collection, you should alway first check that there are that many items in the array/collection

          Comment

          Working...