Parameters.AddWithValue refreshing values

  • Thread starter Thread starter Roy Gourgi
  • Start date Start date
R

Roy Gourgi

Hi,

I would like to know if there is a way of refreshing the
oCommand.Parameters.AddWithValue without having to first clear (i.e.
oCommand.Parameters.Clear() ) and then reinitializing it with
oCommand.Parameters.AddWithValue. Can it be done with one statement?

TIA
Roy
 
Roy Gourgi said:
I would like to know if there is a way of refreshing the
oCommand.Parameters.AddWithValue without having to first clear (i.e.
oCommand.Parameters.Clear() ) and then reinitializing it with
oCommand.Parameters.AddWithValue. Can it be done with one statement?

Well, you're not *adding* a parameter in that case - you're just
changing the value of an existing parameter. So do:

oCommand.Parameters[name].Value=value;
 
Hi Jon,

How could I use the foreach looping statement to iterate through all the
parameter collection so as to be able to assign a new value to each.
For example lets say my I have a collection of 5 parameters each initiated
with a value of 3 and then I want to change the value of each of the 5
parameters from 3 to 6, how could I do that.


foreach(????????????????)
{
oCommand.Parameters[name].Value=6;
}

Thanks
Roy



Jon Skeet said:
Roy Gourgi said:
I would like to know if there is a way of refreshing the
oCommand.Parameters.AddWithValue without having to first clear (i.e.
oCommand.Parameters.Clear() ) and then reinitializing it with
oCommand.Parameters.AddWithValue. Can it be done with one statement?

Well, you're not *adding* a parameter in that case - you're just
changing the value of an existing parameter. So do:

oCommand.Parameters[name].Value=value;
 
Hi Jon,

Is it possible to maybe use an index to set the values instead.
For example if I have a collection of 5 parameters can I use an index to set
their values.

oCommand.Parameters[index0].Value = 6;

Thanks
Roy

Jon Skeet said:
Roy Gourgi said:
I would like to know if there is a way of refreshing the
oCommand.Parameters.AddWithValue without having to first clear (i.e.
oCommand.Parameters.Clear() ) and then reinitializing it with
oCommand.Parameters.AddWithValue. Can it be done with one statement?

Well, you're not *adding* a parameter in that case - you're just
changing the value of an existing parameter. So do:

oCommand.Parameters[name].Value=value;
 
Hi Jon,

It's ok thanks I solved the problem as I used this.

for (lpMisc = 0; lpMisc <= 1; lpMisc++)

{

oCommand.Parameters[lpMisc].Value = laArr[lpMisc];

oCommand.Parameters[lpMisc].Value = laArr[lpMisc];

}



Thanks

Roy

Jon Skeet said:
Roy Gourgi said:
I would like to know if there is a way of refreshing the
oCommand.Parameters.AddWithValue without having to first clear (i.e.
oCommand.Parameters.Clear() ) and then reinitializing it with
oCommand.Parameters.AddWithValue. Can it be done with one statement?

Well, you're not *adding* a parameter in that case - you're just
changing the value of an existing parameter. So do:

oCommand.Parameters[name].Value=value;
 
Roy Gourgi said:
It's ok thanks I solved the problem as I used this.

for (lpMisc = 0; lpMisc <= 1; lpMisc++)

{
oCommand.Parameters[lpMisc].Value = laArr[lpMisc];
oCommand.Parameters[lpMisc].Value = laArr[lpMisc];
}

Why are you doing the assignment twice, out of interest?
 
That is a typo. It worked great though.

Thanks Jon

Roy

Jon Skeet said:
Roy Gourgi said:
It's ok thanks I solved the problem as I used this.

for (lpMisc = 0; lpMisc <= 1; lpMisc++)

{
oCommand.Parameters[lpMisc].Value = laArr[lpMisc];
oCommand.Parameters[lpMisc].Value = laArr[lpMisc];
}

Why are you doing the assignment twice, out of interest?
 
Back
Top