unusual array error at runtime

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ChrisB

    unusual array error at runtime

    Hello:

    I am attempting to execute the following code which was created with Visual
    Studio 2003:

    SqlParameter[] DateParameters = new SqlParameter[5];
    DateParameters[0] = new SqlParameter("@ ConsumerDateID" , _dateID);

    DateParameters[1] = new SqlParameter("@ ConsumerID", Consumer.Consum erID);

    DateParameters[2] = new SqlParameter("@ ConsumerDateTyp eID", _typeID);

    DateParameters[3] = new SqlParameter("@ Value", _value);

    DateParameters[4] = new SqlParameter("@ Index", _index);

    I am receiving the following error each time the runtime attempts to store
    the DateParameter[3] value (error thrown before next line even reached):

    "Index (zero based) must be greater than or equal to zero and less than the
    size of the argument list."

    I have tried closing and recompiling my code on several occasions, and
    altering the size of the array, but cannot get this to execute properly.

    Is there an error in my code? Is there some type of IDE or compilation
    issue that might be causing this?

    Thanks for any insight!

    Chris


  • Jon Skeet [C# MVP]

    #2
    Re: unusual array error at runtime

    ChrisB <pleasereplytog roup@thanks.com > wrote:[color=blue]
    > I am attempting to execute the following code which was created with Visual
    > Studio 2003:
    >
    > SqlParameter[] DateParameters = new SqlParameter[5];
    > DateParameters[0] = new SqlParameter("@ ConsumerDateID" , _dateID);
    >
    > DateParameters[1] = new SqlParameter("@ ConsumerID", Consumer.Consum erID);
    >
    > DateParameters[2] = new SqlParameter("@ ConsumerDateTyp eID", _typeID);
    >
    > DateParameters[3] = new SqlParameter("@ Value", _value);
    >
    > DateParameters[4] = new SqlParameter("@ Index", _index);
    >
    > I am receiving the following error each time the runtime attempts to store
    > the DateParameter[3] value (error thrown before next line even reached):
    >
    > "Index (zero based) must be greater than or equal to zero and less than the
    > size of the argument list."
    >
    > I have tried closing and recompiling my code on several occasions, and
    > altering the size of the array, but cannot get this to execute properly.
    >
    > Is there an error in my code? Is there some type of IDE or compilation
    > issue that might be causing this?[/color]

    Could you post a short but complete program which demonstrates the
    problem? It sounds very odd to me.

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • ChrisB

      #3
      Re: unusual array error at runtime

      Jon:

      I created a small application to demonsrate the issue as you requested, but
      was unable to recreate the error.

      After reviewing the code a bit longer, I was able to determine the source of
      the problem:

      _value contains an object, not a string and had to be changed to _value.date

      // original code
      DateParameters[3] = new SqlParameter("@ Value", _value);

      // changed code
      DateParameters[3] = new SqlParameter("@ Value", _value.date);

      Seems obvious now, but the index error message threw me off quite a bit (my
      head is a little sore from banging it against the wall :>) ).

      Oh well, live and learn!

      Thanks for offering your help.

      Chris


      "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
      news:MPG.1a1447 493eb7315e989a2 a@msnews.micros oft.com...[color=blue]
      > ChrisB <pleasereplytog roup@thanks.com > wrote:[color=green]
      > > I am attempting to execute the following code which was created with[/color][/color]
      Visual[color=blue][color=green]
      > > Studio 2003:
      > >
      > > SqlParameter[] DateParameters = new SqlParameter[5];
      > > DateParameters[0] = new SqlParameter("@ ConsumerDateID" , _dateID);
      > >
      > > DateParameters[1] = new SqlParameter("@ ConsumerID",[/color][/color]
      Consumer.Consum erID);[color=blue][color=green]
      > >
      > > DateParameters[2] = new SqlParameter("@ ConsumerDateTyp eID", _typeID);
      > >
      > > DateParameters[3] = new SqlParameter("@ Value", _value);
      > >
      > > DateParameters[4] = new SqlParameter("@ Index", _index);
      > >
      > > I am receiving the following error each time the runtime attempts to[/color][/color]
      store[color=blue][color=green]
      > > the DateParameter[3] value (error thrown before next line even reached):
      > >
      > > "Index (zero based) must be greater than or equal to zero and less than[/color][/color]
      the[color=blue][color=green]
      > > size of the argument list."
      > >
      > > I have tried closing and recompiling my code on several occasions, and
      > > altering the size of the array, but cannot get this to execute[/color][/color]
      properly.[color=blue][color=green]
      > >
      > > Is there an error in my code? Is there some type of IDE or compilation
      > > issue that might be causing this?[/color]
      >
      > Could you post a short but complete program which demonstrates the
      > problem? It sounds very odd to me.
      >
      > --
      > Jon Skeet - <skeet@pobox.co m>
      > http://www.pobox.com/~skeet
      > If replying to the group, please do not mail me too[/color]


      Comment

      Working...