unusual array error at runtime

  • Thread starter Thread starter ChrisB
  • Start date Start date
C

ChrisB

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.ConsumerID);

DateParameters[2] = new SqlParameter("@ConsumerDateTypeID", _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
 
ChrisB said:
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.ConsumerID);

DateParameters[2] = new SqlParameter("@ConsumerDateTypeID", _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?

Could you post a short but complete program which demonstrates the
problem? It sounds very odd to me.
 
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 said:
ChrisB said:
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.ConsumerID);

DateParameters[2] = new SqlParameter("@ConsumerDateTypeID", _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?

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