471,605 Members | 1,338 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,605 software developers and data experts.

Parameters.AddWithValue refreshing values

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
Dec 4 '05 #1
6 3425
Roy Gourgi <ro***@videotron.ca> wrote:
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;

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 4 '05 #2
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 [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Roy Gourgi <ro***@videotron.ca> wrote:
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;

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Dec 4 '05 #3
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 [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Roy Gourgi <ro***@videotron.ca> wrote:
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;

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Dec 4 '05 #4
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 [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Roy Gourgi <ro***@videotron.ca> wrote:
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;

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Dec 4 '05 #5
Roy Gourgi <ro***@videotron.ca> wrote:
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?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 4 '05 #6
That is a typo. It worked great though.

Thanks Jon

Roy

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Roy Gourgi <ro***@videotron.ca> wrote:
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?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Dec 5 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Tim::.. | last post: by
reply views Thread by digitalcolony | last post: by
reply views Thread by =?Utf-8?B?VGVycnkgSG9sbGFuZA==?= | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by MichaelMortimer | last post: by
reply views Thread by CCCYYYY | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.