Missing constructor for SqlParameter (?)

  • Thread starter Thread starter marc
  • Start date Start date
M

marc

It surprises me that there is no constructor for SqlParameter
with parameters for name, the SqlDbType, size AND VALUE (?).

There's of course this constructor :

SqlParameter pm01 = new SqlParameter("@fieldname", SqlDbType.Int, 4);


But then you will always have to set the value separtly, like this :

pm01.Value = 42;
command.Parameters.Add(pm01);


Why is there no better alternative for this ?
Am I missing something here ?
 
It surprises me that there is no constructor for SqlParameter
with parameters for name, the SqlDbType, size AND VALUE (?).

There's of course this constructor :

SqlParameter pm01 = new SqlParameter("@fieldname", SqlDbType.Int, 4);


But then you will always have to set the value separtly, like this :

pm01.Value = 42;
command.Parameters.Add(pm01);

Why is there no better alternative for this ?
Am I missing something here ?

I suspect it's because the common use for parameters is to set them up
once, and then use them multiple times with different values. The
constructor effectively sets up the constant parts, and then you go
through a loop of "set value, execute command".

Just a guess though.
 
Back
Top