0

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.