Chad
Chad

Reputation: 24699

SqlParameter object: Why do I need to mess with all the options?

When I call a stored procedure from .NET code, I could you this to specify a param value:

sqlCommand.Parameters.AddWithValue("@param1", myvalue1);

If I am calling a SQL Server stored procedure, is there ever a need to specify other optional SqlParameter property values such as Length, datatype, precision, etc, when I am calling a SQL Server stored procedure?

When is it necesary?

Upvotes: 0

Views: 69

Answers (1)

Oded
Oded

Reputation: 499302

You need to declare the extra parameters when you are dealing with a datatype that requires them.

For example - you can't use the simple overload with floating point data types, as you must specify the precision and scale as defined on the server.

When not specifying them on a type that requires them, you will get a SqlException with a descriptive message to this effect.

In such cases, you can't use AddWithValue, but need to use Add passing in a SqlParameter object.

Upvotes: 1

Related Questions