?
Solved

SQLHelper Problem with Decimal DataType

Posted on 2009-05-18
6
Medium Priority
?
708 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 

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

Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

770 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