SQLHelper Problem with Decimal DataType

Posted on 2009-05-18
Last Modified: 2013-11-26
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?
Question by:TaibaDXB
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

Expert Comment

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?

Author Comment

ID: 24419082
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.

Expert Comment

ID: 24421795
Can you post the declaration and assignment of TotalAmount?
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.


Author Comment

ID: 24423249
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)

Accepted Solution

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:
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.

Expert Comment

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

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 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