1

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?

RecMenDat
  • 11
  • 1

2 Answers2

1

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

Davita
  • 8,928
  • 14
  • 67
  • 119
0

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

Tobias Schittkowski
  • 2,221
  • 2
  • 16
  • 25