Is there an overload to add sqlparameters with name, type, value

364 Views Asked by At

When adding parameters to a SQLCommand, is there an overload that includes 'parameter name', 'type and 'value' otherwise i end up writing something like:

using cmd as new SQLCommand("SELECT x FROM y WHERE z = @z", cn)
  Dim p0 as SQLParameter = cmd.Parameters.Add("@z", SQLDbType.Int)
  p0.Value = 1
end using

I would like a one liner for adding the parameter.

Is there a better method of adding the parameter?

2

There are 2 best solutions below

0
On

You can use extension methods (VB.NET 3.5) to write the new Add method with 3 arguments...

http://msdn.microsoft.com/en-us/library/bb384936.aspx

1
On

I'm not fluent with VB, but this should work

Dim p0 as SQLParameter = cmd.Parameters.Add(new SQLParameter("@z", 1)) 

The parameter will be resolved automatically