473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

SQLServer saves Decimal as Integer

I am using the Data Access Application Block for a data
interface tier in my application. All data goes to and
from the database (MSDE) without a problem, except for
decimal numbers which get stored as integers. I can set
the numbers to decimal values using the Server Explorer,
but the next time I save them they are converted to
integers again.

I use the following command to update the database:
SqlHelper.ExecuteNonQuery
(conn2,CommandType.StoredProcedure,strCmd,sqlParms );

The decimal numbers are passed into the method as
follows:
sqlParms[5] = new SqlParameter("@WeightPerPiece",
SqlDbType.Decimal, 8);
sqlParms[5].Value = 7.5;

This is always stored as 8. What is wrong?
Nov 15 '05 #1
3 3628
"gaius" <jd******@ieee.org> wrote in message
news:05****************************@phx.gbl...
I am using the Data Access Application Block for a data
interface tier in my application. All data goes to and
from the database (MSDE) without a problem, except for
decimal numbers which get stored as integers. I can set
the numbers to decimal values using the Server Explorer,
but the next time I save them they are converted to
integers again.

I use the following command to update the database:
SqlHelper.ExecuteNonQuery
(conn2,CommandType.StoredProcedure,strCmd,sqlParms );

The decimal numbers are passed into the method as
follows:
sqlParms[5] = new SqlParameter("@WeightPerPiece",
SqlDbType.Decimal, 8);
sqlParms[5].Value = 7.5;

This is always stored as 8. What is wrong?


Have you called your stored procedure using Query Analyzer to make sure the
problem doesn't lie with the sproc itself? Quite often I've seen sprocs
written where a decimal parameter was defined incorrectly (wrong
scale/precision) or accidentally defined as an int.

If you can run the stored procedure from QA and the value is stored
correctly, then you can point the finger at the C# code. But given what
you've shown above, I'd definitely look again at the sproc itself.

Good luck,
Ryan LaNeve
Nov 15 '05 #2
gaius <jd******@ieee.org> wrote:
I am using the Data Access Application Block for a data
interface tier in my application. All data goes to and
from the database (MSDE) without a problem, except for
decimal numbers which get stored as integers. I can set
the numbers to decimal values using the Server Explorer,
but the next time I save them they are converted to
integers again.

I use the following command to update the database:
SqlHelper.ExecuteNonQuery
(conn2,CommandType.StoredProcedure,strCmd,sqlParms );

The decimal numbers are passed into the method as
follows:
sqlParms[5] = new SqlParameter("@WeightPerPiece",
SqlDbType.Decimal, 8);
sqlParms[5].Value = 7.5;

This is always stored as 8. What is wrong?


Have you tried setting the value to 7.5m instead of 7.5? That would be
the C# decimal value instead of the double value. Just a guess
though...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3
Thanks Ryan, you were right. The problem was in the definition of the
ContainerWeight varialbe in the stored procedure. I had specified it as
follows:
@ContainerWeight decimal

I needed to provide the scale and precision as follows:
@ContainerWeight decimal(7,3)

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
4
by: italia | last post by:
I changed the Fieldsize Property from text to Long Integer and Decimal Places = 6. I had decimals in the original field. But after the transfer, the digits after the decimals are gone. Now...
0
by: gaius | last post by:
I am using the Data Access Application Block for a data interface tier in my application. All data goes to and from the database (MSDE) without a problem, except for decimal numbers which get...
5
by: Paperback Writer | last post by:
Hi, i have in my application a field that is percentual, that means...can have comma...my property that receive this data is a decimal and in my SQLServer is also a decimal, but when i type, for...
11
by: ChrisM | last post by:
Hi Guys, I'm looking for a function that will return the lowest integer that is greater than or equal to a decimal number. eg. 3.1(decimal) returns 4(integer) 3.9(decimal) returns...
4
by: =?Utf-8?B?UmljaA==?= | last post by:
Is there a way to determine if a numeric value contains a decimal? how to do this? If IsNumeric(txt1.Text) then ... so now I know that txt1.Text is a numeric value. How can I tell if it is a...
12
by: Frank Millman | last post by:
Hi all I have a standard requirement for a 'decimal' type, to instantiate and manipulate numeric data that is stored in a database. I came up with a solution long before the introduction of the...
13
by: =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= | last post by:
Hi, Why does Math.Sqrt() only accept a double as a parameter? I would think it would be just as happy with a decimal (or int, or float, or ....). I can easily convert back and forth, but I am...
10
by: Jason | last post by:
I'm making a program that will convert decimal inputs (in this case, in inches) and output a fractional answer. At the moment, I'm only able to output the fractional answer in three parts: A whole...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.