views:

1579

answers:

3

I have 5 parameters and I want to send them to the method:

public static SqlCommand getCommand(string procedure, SqlParameter[] parameter)
{
   Sqlcommand cmd;
   return cmd
}

Can I send these paramters at one time like this?

SqlParameterCollection prm;
prm.Add(p1);
prm.Add(p2);
prm.Add(p3);
prm.Add(p4);
prm.Add(p5);
sqlcommand cmd = getCommand(prm);
+2  A: 

I don't see what's wrong with that? You do know that, if this is .Net, you need to attach the parameters to the SqlCommand object?

So:

SqlCommand query = new SqlCommand(sqlString, Connection) query.Parameters.AddWithValue(parameter,valueToPass)

etc?

Sorry if that's not related, not completely sure on your question? Your method doesn't really do anything, I take you left out the code and just put in a dummy for the purposes of asking the question? You can pass an array as an arguement so you just need to spilt it up?

Damien
+1  A: 

Well, that won't compile because in your call to getCommand you're not passing in a string with the procedure, but as far as the array, that should work no problem.

BFree
+1  A: 

Or create an array of parameters by hand:

SqlParameter[] parameter = {
new SqlParameter(...), 
new SqlParameter(...), 
new SqlParameter(...)
};

But I don't see what should be wrong with your approach. It simple, readable and understendable.

Drejc