Solved

SQLHelper Problem with Decimal DataType

Posted on 2009-05-18
6
701 Views
Last Modified: 2013-11-26
Hi.
I have a strange problem with SQLHelper from the Enterprise Library.
I am using a statement like the following:

SqlHelper.ExecuteScalar(SqlHelper.ConnStr, "InsertTotalAmount", TotalAmount);

The InsertTotalAmount SP will insert the TotalAmount to a field with Decimal(38,23) Type.
This statement works fine with values less than 99999, but gives me an error with greater than 99999, the error is: "Conversion overflows".
The Decimal(38,23) Type should be enough for storing values like: 1,000,000 !!
what is worng with SQLHelper?
0
Comment
Question by:TaibaDXB
  • 3
  • 3
6 Comments
 
LVL 9

Expert Comment

by:cdaly33
ID: 24416813
What happens if you run the stored proc on its own using the same values?  Are you doing any multiplication or division in the stored proc which might affect the accuracy of the decimal?
0
 

Author Comment

by:TaibaDXB
ID: 24419082
Hi.
if I run the stored proc directly with the same values, it rus correctly without any problems!!
The stored proc just inserts the value into the table without doing any arithmatic operation.
Thanks for you rhelp.
0
 
LVL 9

Expert Comment

by:cdaly33
ID: 24421795
Can you post the declaration and assignment of TotalAmount?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:TaibaDXB
ID: 24423249
Hi.
Total amount is declared in .NET as Decimal.
Its value is entered by the user like the following:
Decimal totalAmount = Convert.ToDecimal(txtTotalAmount.Text);
In SQL Server 2008 it is declared in the table as : decimal(38,23)
0
 

Accepted Solution

by:
TaibaDXB earned 0 total points
ID: 24468067
I have found the cause for this problem.
It is a bug in .NET as described in these links:
http://tjoe.wordpress.com/2007/04/
http://support.microsoft.com/kb/932288
It is all about the difference between The Decimal type in SQL Server and the Decimal type in .NET
In SQL the maximum precision is 38, but in .NET it is 28. which makes the overflow.
0
 
LVL 9

Expert Comment

by:cdaly33
ID: 24468107
Wow, great find.  That's great to know.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question