Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Converting string to numeric
Message
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01544642
Message ID:
01544689
Views:
22
>>>>>>>>>When I change to the following:
>>>>>>>>>
>>>>>>>>>param.SqlDbType = System.Data.SqlDbType.Decimal;
>>>>>>>>>param.Value = 0.00;  
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>I get compiler error.
>>>>>>>>
>>>>>>>>What?
>>>>>>>
>>>>>>>What I wrote in the other message about "The explicit conversion exists (are you missing a cast?)"
>>>>>>
>>>>>>
>>>>>>That works for me:
>>>>>>
>>>>>> SqlCommand sql = new SqlCommand();
>>>>>>sql.Parameters.Add("asd");
>>>>>>sql.Parameters[0].SqlDbType = SqlDbType.Decimal;
>>>>>>sql.Parameters[0].Size = 10;
>>>>>>sql.Parameters[0].Value = 0.00;
>>>>>>sql.Parameters[0].Direction = ParameterDirection.InputOutput;
>>>>>>
>>>>>
>>>>>The above code does not produce the compilere error. But when I call the stored procedure I get error "Error converting data type numeric to numeric"
>>>>
>>>>Try Naomi's suggestion with Precision and Scale.
>>>
>>>I will; thank you. But does setting the type in my stored procedure as "numeric(10,2)" correct?
>>
>>Sure Numeric is fine.
>
>Here is one thing that seems to be strange to me. As I mentioned to William, if I comment out the line that set the data type (SqlDbType) and set the value as following:
>
>
>sql.Parameters[0].value = "6.61";
>
>
>everything works. I don't understand how it works since the number is in quotes. But the value that is passed to the stored procedure is numeric. But it works so I should not complain <g>.

:-)
It works because SQL Server is smart enough to do implicit conversion of the values.
You always can use SQL Profiler t see what your application send to SQL Server.
This is the best tool to test your queries.
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform