What is the simplest way to set up parameters?

  • Thread starter Thread starter Rob Richardson
  • Start date Start date
R

Rob Richardson

Greetings!

I am trying to figure out the easiest way to set up parameters for an insert
query. There are lots of overloads for the OleDbCommand.Parameters.Add()
method and lots more of them for the OleDbParameter constructor, and I'm
suffering from overload overload. I will be adding simple data types:
strings, currency values, and integers. Is a two-step process best?

dim newParameter as OleDbParameter = myCommand.Parameters.Add("ParamName",
OleDbtype.Char)
newParameter.Value = "ValueIWantInMyDatabase"

What parameters of the OleDbParameter structure do I need to fill in, and
what will be filled in for me? Do I need to fill in the size for string
parameters, even though VB should know what the size is? Do I need to fill
in scale and precision for integer or currency parameters?

Thanks!

Rob
 
Rob:
Rob Richardson said:
Greetings!

I am trying to figure out the easiest way to set up parameters for an insert
query. There are lots of overloads for the OleDbCommand.Parameters.Add()
method and lots more of them for the OleDbParameter constructor, and I'm
suffering from overload overload. I will be adding simple data types:
strings, currency values, and integers. Is a two-step process best?

dim newParameter as OleDbParameter = myCommand.Parameters.Add("ParamName",
OleDbtype.Char)
newParameter.Value = "ValueIWantInMyDatabase"

What parameters of the OleDbParameter structure do I need to fill in, and
what will be filled in for me? Do I need to fill in the size for string
parameters, even though VB should know what the size is? Do I need to fill
in scale and precision for integer or currency parameters?

Thanks!

Rob
You can use the first method and still do it in one swoop:

Dim newParameter as OleDbParameter = myCommand.Parameters.Add("ParamName",
OleDbtype.Char).Value = "ValueIWantInMyDatabase"

Technically, you don't even need to include the type and since you are using
OleDb, I don't think you even need to use a name... However, as with most
things, everything you don't include that isn't defaulted, the computer has
to figure out for you. Moreover, it can have the unwanted side effect of
working for reasons that you don't understand. I personally specify type
and precsion-- if for no other reason then to document what I really am
intending to do. So where possible, I'd advise being as explicit as
possible however, technically, you don't have to specify much of anything.

HTH,

Bill
 
Back
Top