473,320 Members | 1,854 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,320 software developers and data experts.

Return a decimal value

Dear Sir,

I am trying to get one decimal value from DB. However, every time, I got an
INT back instead of decimal. For example, if I have 4.75 in DB, I will get a
5 back.

The followings are example of my code. What did I do wrong?
' for output parameters.
Dim objOutputPara As New SqlParameter("@r", SqlDbType.Decimal, 9)
myCommand.Parameters.Add(objOutputPara)
objOutputPara.Direction = ParameterDirection.Output
' Open the connection.
myConnection.Open()
myCommand.ExecuteReader()
ReturnValue = objOutputPara.Value

Below is my stored procedure.

CREATE PROCEDURE MyProc_BookingGetInputHours
@UserId int,
@ActivityId int,
@BookDate smallDatetime,
@r decimal(10,2) = 0 output
AS
Set @r = 0
IF Exists (Select * FROM tblBooking WHERE ActivityId=@ActivityId and
UserId=@UserId and BookDate = @BookDate)
BEGIN
SELECT @r = Hours FROM tblBooking WHERE ActivityId=@ActivityId and
UserId=@UserId and BookDate = @BookDate
END

IF @r = Null
set @r =0
GO

--
Kind regards

Guoqi Zheng
guoqi AT meetholland dot com
Http://www.meetholland.com

Nov 18 '05 #1
2 1391
What is ReturnValue defined as?
On Mon, 28 Jun 2004 08:14:33 +0200, "Guoqi Zheng" <no@sorry.nl> wrote:
Dear Sir,

I am trying to get one decimal value from DB. However, every time, I got an
INT back instead of decimal. For example, if I have 4.75 in DB, I will get a
5 back.

The followings are example of my code. What did I do wrong?
' for output parameters.
Dim objOutputPara As New SqlParameter("@r", SqlDbType.Decimal, 9)
myCommand.Parameters.Add(objOutputPara)
objOutputPara.Direction = ParameterDirection.Output
' Open the connection.
myConnection.Open()
myCommand.ExecuteReader()
ReturnValue = objOutputPara.Value

Below is my stored procedure.

CREATE PROCEDURE MyProc_BookingGetInputHours
@UserId int,
@ActivityId int,
@BookDate smallDatetime,
@r decimal(10,2) = 0 output
AS
Set @r = 0
IF Exists (Select * FROM tblBooking WHERE ActivityId=@ActivityId and
UserId=@UserId and BookDate = @BookDate)
BEGIN
SELECT @r = Hours FROM tblBooking WHERE ActivityId=@ActivityId and
UserId=@UserId and BookDate = @BookDate
END

IF @r = Null
set @r =0
GO


Nov 18 '05 #2
ReturnValue is defined as decimal...

I have found out what the problem is... I need to define scale for it...
--
Kind regards

Guoqi Zheng
guoqi AT meetholland dot com
Http://www.meetholland.com

"Dan Brussee" <db******@nc.rr.com> wrote in message
news:f2********************************@4ax.com...
What is ReturnValue defined as?
On Mon, 28 Jun 2004 08:14:33 +0200, "Guoqi Zheng" <no@sorry.nl> wrote:
Dear Sir,

I am trying to get one decimal value from DB. However, every time, I got anINT back instead of decimal. For example, if I have 4.75 in DB, I will get a5 back.

The followings are example of my code. What did I do wrong?
' for output parameters.
Dim objOutputPara As New SqlParameter("@r", SqlDbType.Decimal, 9)
myCommand.Parameters.Add(objOutputPara)
objOutputPara.Direction = ParameterDirection.Output
' Open the connection.
myConnection.Open()
myCommand.ExecuteReader()
ReturnValue = objOutputPara.Value

Below is my stored procedure.

CREATE PROCEDURE MyProc_BookingGetInputHours
@UserId int,
@ActivityId int,
@BookDate smallDatetime,
@r decimal(10,2) = 0 output
AS
Set @r = 0
IF Exists (Select * FROM tblBooking WHERE ActivityId=@ActivityId and
UserId=@UserId and BookDate = @BookDate)
BEGIN
SELECT @r = Hours FROM tblBooking WHERE ActivityId=@ActivityId and
UserId=@UserId and BookDate = @BookDate
END

IF @r = Null
set @r =0
GO

Nov 18 '05 #3

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

Similar topics

3
by: Phil Powell | last post by:
My first time working with a PHP class, and after 6 hours of working out the kinks I am unable to return a value from the class, so now I appeal to the general audience what on earth did I do wrong...
21
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing/modifying the code. Thank you. .. Facundo
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....
10
by: Paul Sullivan | last post by:
decimal d; d = 1.1M OR d= (decimal) 1.1 Discussioon
15
by: Bernard Bourée | last post by:
I have the following code: Dim mVar As New Variable() mVar.NomVal = "Test" ==> this line return a NomVal ="Test" mVar.oVal = 10D ====> but this one return a oVal= NOTHING !!!! What...
12
by: Sheldon | last post by:
#define UWORD2 unsigned short int typedef BYTE Boolean; Boolean evaluateBit(UWORD2 *value, int bitnumber); Boolean evaluateBit(UWORD2 *value, int bitnumber) { int one=1; return (one &(*value...
4
by: =?Utf-8?B?cGF0cmlja2RyZA==?= | last post by:
Hi everyone! I'm using greece - greek in my control panel's regional options, and so, my decimal point is the comma (,), while it is the dot (.) for the sql server db, however, I'm facing...
15
by: Sunburned Surveyor | last post by:
I'm a Java developer in the process of writing a class library in C#, so please bear with me. I'm trying to write a method that can return a generic Object OR a Decimal value. In Java I would...
1
by: iquttaineh | last post by:
Hi, I have a stored procedure that executed in SQL Server 2000 that returns a decimal SUM value, the stored procedure executed successfully in Query Analyzer and returns the correct value, but when...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.