0

I want to execute a stored procedure, and give it a parameter like this:

new SqlParameter("@ResidualValue", importExportOptions.ResidualValue)

ResidualValue is of type decimal, and in the database, it has type Money. Now I've been looking for an answer of course, and found the following:

"Just initialize the Parameter with a new SqlMoney(decimal) constructor. SqlParameter parameter = new SqlParameter("@Money", SqlDbType.Money);"

But adding SqlDbType.Money does not give me the option to specify the value importExportOptions.ResidualValue anymore. What can I do?

1 Answer 1

3

I think you are looking for something this;

command.Parameters.Add(
    new SqlParameter("@ResidualValue", SqlDbType.Money).Value = importExportOptions.ResidualValue;

Though this syntax is now deprecated as this quote from MSDN shows:

AddWithValue replaces the SqlParameterCollection.Add method that takes a String and an Object. The overload of Add that takes a string and an object was deprecated because of possible ambiguity with the SqlParameterCollection.Add overload that takes a String and a SqlDbType enumeration value where passing an integer with the string could be interpreted as being either the parameter value or the corresponding SqlDbType value. Use AddWithValue whenever you want to add a parameter by specifying its name and value.

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparametercollection.addwithvalue%28v=vs.110%29.aspx

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.