Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Converting string to numeric
Message
From
30/05/2012 02:04:32
 
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01544642
Message ID:
01544731
Views:
24
>Yet another question on setting up values to parameters to be passed to a sql server stored procedure.
>
>Here is an example.
>One of the parameters of the stored procedure is of type number:
>
>
>@nTest numeric(10,2) OUTPUT
>--- set value
>set @nTest = 3333.33
>
>
>Then in the C# code when creating the parameter I do the following
>
>param.DbType = System.Data.DbType.Decimal;
>param.Value = 0;
>param.Direction.InputOutput;
>
>
>But after I call the oCommand.ExecuteNonQuery() I get error
>
>
>Error converting data type numeric to numeric
>
>
>What am I missing?
>
>TIA.
>
>UPDATE: The title of the thread is wrong. It should have said, Using Decimal type parameter.

I haven't read the whole thread but I think it is important that you understand the underlying cause of the problem:
(a) Parameter.Value is an *object* so will accept whatever type you throw at it.
(b) You need to be aware of how numerica literals are cast:
param.Value = 0 ; //integer
=0.00 //double
=0.00m //decimal
(c) Finally understand how C# types are mapped to SQLTypes - see "Specifying parameter datatypes" here:
http://msdn.microsoft.com/en-us/library/yy6y35y8.aspx

If you are clear on the above then you should be able to avoid this type of problem in the future....
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform