SeaDrive
SeaDrive

Reputation: 4292

SqlCommand Parameter not recognized

Why does

        scIns.Parameters.Add(new SqlParameter("@v30", 0.00m));

lead to a "@v30 undefined" error, but

        decimal dZero = 0.00m;
        scIns.Parameters.Add(new SqlParameter("@v30", dZero));

works OK?

Upvotes: 2

Views: 995

Answers (2)

Jethro
Jethro

Reputation: 5916

SqlParamter has two different overloads with two parameters, first being string and second being SqlDbType or object.

In the first case when 0.00m gets passed in it gets converted to Int64, and in the second case because the value passed in is of type decimal it then used the SqlDbType.Decimal.

Check out this Link

Update :
Found another stackoverflow Question that talks about this and has a detailed answer. :)

Upvotes: 3

JohnD
JohnD

Reputation: 14747

If you look in the debugger, you will see that in the first case, the parameter's DbType is Int64, and in the second case it's Decimal.

Try using one of the other SqlParameter ctor overloads where you explicitly specify the SqlDbType.

Hope that helps,

John

Upvotes: 1

Related Questions