473,569 Members | 2,597 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parameter list

Hi,

Is there a way to add a parameter list with only one statement as opposed to
having one statement for each parameter. For example if I have 20 parameters
(@p1, @p2 .... @p20) that I want to add to my parameter collection, could I
do it all in one statement more or less?

TIA
Roy
Dec 6 '05 #1
8 1713
Could you make it more clear.
If you are saying about collection, many classes expose AddRange
method.
Note that Array also implement ICollection.

Dec 6 '05 #2
I believe that the OP is referring to SQL parameters.

Dec 6 '05 #3
Ah yes, I didn't notice that.
So he just needs to write a helper method to do that.

Dec 6 '05 #4
Hi Truong,

What I mean is this. When I first add my parameters I do it like this (see
below), so I was wandering if there was a way to do this all in one
statement rather than 10 statements. I guess I could use a for loop and a
string builder to do it, but I was wandering if there was an inherent way to
do it.
oCommand.Parame ters.AddWithVal ue("@par0", laEnum2Bk[0]);
oCommand.Parame ters.AddWithVal ue("@par1", laEnum2Bk[1]);

oCommand.Parame ters.AddWithVal ue("@par2", laEnum2Bk[2]);

oCommand.Parame ters.AddWithVal ue("@par3", laEnum2Bk[3]);

oCommand.Parame ters.AddWithVal ue("@par4", laEnum2Bk[4]);

oCommand.Parame ters.AddWithVal ue("@par5", laEnum2Bk[5]);

oCommand.Parame ters.AddWithVal ue("@par6", laEnum2Bk[6]);

oCommand.Parame ters.AddWithVal ue("@par7", laEnum2Bk[7]);

oCommand.Parame ters.AddWithVal ue("@par8", laEnum2Bk[8]);

oCommand.Parame ters.AddWithVal ue("@par9", laEnum2Bk[9]);

oCommand.Parame ters.AddWithVal ue("@par10", laEnum2Bk[10]);

Thanks

Roy

"Truong Hong Thi" <th*****@gmail. com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Could you make it more clear.
If you are saying about collection, many classes expose AddRange
method.
Note that Array also implement ICollection.

Dec 6 '05 #5
As Truong Hong Thi said, a helper function is probably the way to go... I'm
assuming (from the AddWithValue method) that the command is a SqlCommand,
not an IDbCommand, so how about the following:

public static void AddCommandParam s(SqlCommand command, string prefix,
params object[] values) {
int index = 0;
foreach (object value in values) {
command.Paramet ers.AddWithValu e(prefix+(index ++).ToString(), value);
}
}

Then call
AddCommandParam s(oCommand, "@par", laEnum2Bk);

The "params" is so that you could also call:
AddCommandParam s(oCommand, "@par", "MyValue", 1, 0.2);

Haven't tested the code, but looks like it should work (famous last
words...)

Marc

"Roy Gourgi" <ro***@videotro n.ca> wrote in message
news:VK******** *********@wagne r.videotron.net ...
Hi Truong,

What I mean is this. When I first add my parameters I do it like this (see
below), so I was wandering if there was a way to do this all in one
statement rather than 10 statements. I guess I could use a for loop and a
string builder to do it, but I was wandering if there was an inherent way
to do it.
oCommand.Parame ters.AddWithVal ue("@par0", laEnum2Bk[0]);
oCommand.Parame ters.AddWithVal ue("@par1", laEnum2Bk[1]);

oCommand.Parame ters.AddWithVal ue("@par2", laEnum2Bk[2]);

oCommand.Parame ters.AddWithVal ue("@par3", laEnum2Bk[3]);

oCommand.Parame ters.AddWithVal ue("@par4", laEnum2Bk[4]);

oCommand.Parame ters.AddWithVal ue("@par5", laEnum2Bk[5]);

oCommand.Parame ters.AddWithVal ue("@par6", laEnum2Bk[6]);

oCommand.Parame ters.AddWithVal ue("@par7", laEnum2Bk[7]);

oCommand.Parame ters.AddWithVal ue("@par8", laEnum2Bk[8]);

oCommand.Parame ters.AddWithVal ue("@par9", laEnum2Bk[9]);

oCommand.Parame ters.AddWithVal ue("@par10", laEnum2Bk[10]);

Thanks

Roy

"Truong Hong Thi" <th*****@gmail. com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Could you make it more clear.
If you are saying about collection, many classes expose AddRange
method.
Note that Array also implement ICollection.


Dec 6 '05 #6
Hi Marc,

I tried this and it seems to work fine for my needs. BTW would this be
faster if I used a string builder?

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

{

strC = "@par"+lpMisc.T oString();

oCommand.Parame ters.AddWithVal ue(strC, laEnum2Bk[lpMisc]);

}

Thanks
Roy

"Marc Gravell" <mg******@rm.co m> wrote in message
news:%2******** ************@tk 2msftngp13.phx. gbl...
As Truong Hong Thi said, a helper function is probably the way to go...
I'm assuming (from the AddWithValue method) that the command is a
SqlCommand, not an IDbCommand, so how about the following:

public static void AddCommandParam s(SqlCommand command, string prefix,
params object[] values) {
int index = 0;
foreach (object value in values) {

command.Paramet ers.AddWithValu e(prefix+(index ++).ToString(), value);
}
}

Then call
AddCommandParam s(oCommand, "@par", laEnum2Bk);

The "params" is so that you could also call:
AddCommandParam s(oCommand, "@par", "MyValue", 1, 0.2);

Haven't tested the code, but looks like it should work (famous last
words...)

Marc

"Roy Gourgi" <ro***@videotro n.ca> wrote in message
news:VK******** *********@wagne r.videotron.net ...
Hi Truong,

What I mean is this. When I first add my parameters I do it like this
(see below), so I was wandering if there was a way to do this all in one
statement rather than 10 statements. I guess I could use a for loop and a
string builder to do it, but I was wandering if there was an inherent way
to do it.
oCommand.Parame ters.AddWithVal ue("@par0", laEnum2Bk[0]);
oCommand.Parame ters.AddWithVal ue("@par1", laEnum2Bk[1]);

oCommand.Parame ters.AddWithVal ue("@par2", laEnum2Bk[2]);

oCommand.Parame ters.AddWithVal ue("@par3", laEnum2Bk[3]);

oCommand.Parame ters.AddWithVal ue("@par4", laEnum2Bk[4]);

oCommand.Parame ters.AddWithVal ue("@par5", laEnum2Bk[5]);

oCommand.Parame ters.AddWithVal ue("@par6", laEnum2Bk[6]);

oCommand.Parame ters.AddWithVal ue("@par7", laEnum2Bk[7]);

oCommand.Parame ters.AddWithVal ue("@par8", laEnum2Bk[8]);

oCommand.Parame ters.AddWithVal ue("@par9", laEnum2Bk[9]);

oCommand.Parame ters.AddWithVal ue("@par10", laEnum2Bk[10]);

Thanks

Roy

"Truong Hong Thi" <th*****@gmail. com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Could you make it more clear.
If you are saying about collection, many classes expose AddRange
method.
Note that Array also implement ICollection.



Dec 6 '05 #7
Re StringBuilder, probably not;

I'm going to take a liberty here and direct you at Jon Skeet's excellent
page on the subject (http://www.yoda.arachsys.com/csharp/stringbuilder.html)
(I hope you don't mind, Jon)

If you were constantly adding to a single string (i.e you were building up
some uber-command as a string (or a CSV or something) by enumerating through
a large-ish array) then maybe - but you're not. For concatenating 2 strings,
the + operator is almost certainly faster by a mile.

As a minor note, I'm sure your underlying code deals with this, but remember
that the array is 0-based (your code enumerates from 1, which is perfectly
valid, but sometimes a bug).

Marc

"Roy Gourgi" <ro***@videotro n.ca> wrote in message
news:uI******** **********@wagn er.videotron.ne t...
Hi Marc,

I tried this and it seems to work fine for my needs. BTW would this be
faster if I used a string builder?

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

{

strC = "@par"+lpMisc.T oString();

oCommand.Parame ters.AddWithVal ue(strC, laEnum2Bk[lpMisc]);

}

Thanks
Roy

"Marc Gravell" <mg******@rm.co m> wrote in message
news:%2******** ************@tk 2msftngp13.phx. gbl...
As Truong Hong Thi said, a helper function is probably the way to go...
I'm assuming (from the AddWithValue method) that the command is a
SqlCommand, not an IDbCommand, so how about the following:

public static void AddCommandParam s(SqlCommand command, string prefix,
params object[] values) {
int index = 0;
foreach (object value in values) {

command.Paramet ers.AddWithValu e(prefix+(index ++).ToString(), value);
}
}

Then call
AddCommandParam s(oCommand, "@par", laEnum2Bk);

The "params" is so that you could also call:
AddCommandParam s(oCommand, "@par", "MyValue", 1, 0.2);

Haven't tested the code, but looks like it should work (famous last
words...)

Marc

"Roy Gourgi" <ro***@videotro n.ca> wrote in message
news:VK******** *********@wagne r.videotron.net ...
Hi Truong,

What I mean is this. When I first add my parameters I do it like this
(see below), so I was wandering if there was a way to do this all in one
statement rather than 10 statements. I guess I could use a for loop and
a string builder to do it, but I was wandering if there was an inherent
way to do it.
oCommand.Parame ters.AddWithVal ue("@par0", laEnum2Bk[0]);
oCommand.Parame ters.AddWithVal ue("@par1", laEnum2Bk[1]);

oCommand.Parame ters.AddWithVal ue("@par2", laEnum2Bk[2]);

oCommand.Parame ters.AddWithVal ue("@par3", laEnum2Bk[3]);

oCommand.Parame ters.AddWithVal ue("@par4", laEnum2Bk[4]);

oCommand.Parame ters.AddWithVal ue("@par5", laEnum2Bk[5]);

oCommand.Parame ters.AddWithVal ue("@par6", laEnum2Bk[6]);

oCommand.Parame ters.AddWithVal ue("@par7", laEnum2Bk[7]);

oCommand.Parame ters.AddWithVal ue("@par8", laEnum2Bk[8]);

oCommand.Parame ters.AddWithVal ue("@par9", laEnum2Bk[9]);

oCommand.Parame ters.AddWithVal ue("@par10", laEnum2Bk[10]);

Thanks

Roy

"Truong Hong Thi" <th*****@gmail. com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Could you make it more clear.
If you are saying about collection, many classes expose AddRange
method.
Note that Array also implement ICollection.



Dec 6 '05 #8
Thanks Marc.

Roy

"Marc Gravell" <mg******@rm.co m> wrote in message
news:uB******** ********@TK2MSF TNGP15.phx.gbl. ..
Re StringBuilder, probably not;

I'm going to take a liberty here and direct you at Jon Skeet's excellent
page on the subject
(http://www.yoda.arachsys.com/csharp/stringbuilder.html) (I hope you don't
mind, Jon)

If you were constantly adding to a single string (i.e you were building up
some uber-command as a string (or a CSV or something) by enumerating
through a large-ish array) then maybe - but you're not. For concatenating
2 strings, the + operator is almost certainly faster by a mile.

As a minor note, I'm sure your underlying code deals with this, but
remember that the array is 0-based (your code enumerates from 1, which is
perfectly valid, but sometimes a bug).

Marc

"Roy Gourgi" <ro***@videotro n.ca> wrote in message
news:uI******** **********@wagn er.videotron.ne t...
Hi Marc,

I tried this and it seems to work fine for my needs. BTW would this be
faster if I used a string builder?

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

{

strC = "@par"+lpMisc.T oString();

oCommand.Parame ters.AddWithVal ue(strC, laEnum2Bk[lpMisc]);

}

Thanks
Roy

"Marc Gravell" <mg******@rm.co m> wrote in message
news:%2******** ************@tk 2msftngp13.phx. gbl...
As Truong Hong Thi said, a helper function is probably the way to go...
I'm assuming (from the AddWithValue method) that the command is a
SqlCommand, not an IDbCommand, so how about the following:

public static void AddCommandParam s(SqlCommand command, string prefix,
params object[] values) {
int index = 0;
foreach (object value in values) {

command.Paramet ers.AddWithValu e(prefix+(index ++).ToString(), value);
}
}

Then call
AddCommandParam s(oCommand, "@par", laEnum2Bk);

The "params" is so that you could also call:
AddCommandParam s(oCommand, "@par", "MyValue", 1, 0.2);

Haven't tested the code, but looks like it should work (famous last
words...)

Marc

"Roy Gourgi" <ro***@videotro n.ca> wrote in message
news:VK******** *********@wagne r.videotron.net ...
Hi Truong,

What I mean is this. When I first add my parameters I do it like this
(see below), so I was wandering if there was a way to do this all in
one statement rather than 10 statements. I guess I could use a for loop
and a string builder to do it, but I was wandering if there was an
inherent way to do it.
oCommand.Parame ters.AddWithVal ue("@par0", laEnum2Bk[0]);
oCommand.Parame ters.AddWithVal ue("@par1", laEnum2Bk[1]);

oCommand.Parame ters.AddWithVal ue("@par2", laEnum2Bk[2]);

oCommand.Parame ters.AddWithVal ue("@par3", laEnum2Bk[3]);

oCommand.Parame ters.AddWithVal ue("@par4", laEnum2Bk[4]);

oCommand.Parame ters.AddWithVal ue("@par5", laEnum2Bk[5]);

oCommand.Parame ters.AddWithVal ue("@par6", laEnum2Bk[6]);

oCommand.Parame ters.AddWithVal ue("@par7", laEnum2Bk[7]);

oCommand.Parame ters.AddWithVal ue("@par8", laEnum2Bk[8]);

oCommand.Parame ters.AddWithVal ue("@par9", laEnum2Bk[9]);

oCommand.Parame ters.AddWithVal ue("@par10", laEnum2Bk[10]);

Thanks

Roy

"Truong Hong Thi" <th*****@gmail. com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
> Could you make it more clear.
> If you are saying about collection, many classes expose AddRange
> method.
> Note that Array also implement ICollection.
>



Dec 7 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
5691
by: Michael Birkmose | last post by:
Hi, Using gcc the following is possible: int some_function(struct local_struct { int member;} a); This function takes one parameter "a" of the type struct local_struct. This type is declared locally on the paramter list, and only has scope in that function.
3
7195
by: Joe | last post by:
I want to create a method similar to Console.WriteLine where I can pass in an unlimited parameter list. I know how to do this in C++ but have no clue in C#. Thanks for any help, Joe
3
1991
by: tshad | last post by:
How do you get just the parameter list of URL - the part after the ?. For example, http://domain/default.asp?arg1=value&arg2=value&arg3=value I want to get the arg1=value&arg2=value&arg3=value part of the url. What I am trying to do is take that and append it to a rediret to another page. Thanks,
6
1912
by: Maksim Kasimov | last post by:
i have two functions and both of them are to make changes into object field or get some results into caller function: void FooFunc1(FooClass& a) { ... void FooFunc2(FooClass* a) { ... or
1
1797
by: jacuna | last post by:
variables declared in a block or in the parameter list of a function are assumed to be of storage class________ unless specified otherwise
4
1672
by: mast2as | last post by:
Hi everyone I need to come up with an efficient solution to add/remove/access parameters to an object. Lets say I create an object "Cart" and at run time based on the user input, lets say we add to this "Cart" object 3 Oranges 4 Apples and 1 Salad (stupid example I know). Whenever we do something with this cast object we want to be able to...
9
1397
by: TheFlyingDutchman | last post by:
I am trying to use a database written in Python called buzhug. In looking at some of the functions I see this prototype: def create(self,*fields,**kw): I am not clear on what the * and the ** are for or what they represent. Or, what are they referred to as so I can do a query for information on them.
3
2981
mafaisal
by: mafaisal | last post by:
End of parameter list expected. Cannot define parameters after a paramarray parameter. Public Sub F_Bind(ByVal StrSql As String, ByVal ParamArray Ctrls() As Object,Optional ByVal Row as Integer =0) End sub Please give soln for this error
6
1426
by: HillBilly | last post by:
One question I have not figured out is how to learn which event parameter list is supported by a control? EventArgs, CommandEventArgs, what?
0
7628
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7938
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8145
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7694
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6317
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5245
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3679
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2128
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1236
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.