Decimals passing problem.
-
Decimals problem. I have a stored procedure that returns values as decimals if I run it on query analyzer. The problem I have is that when the value is passed to my asp.net application the decimal places disappear and the values are rounded to the nearest whole number. Here is my stored procedure: CREATE PROCEDURE sproc_GetTown ( @Town varchar(100), @TdPermUnits As int OUTPUT, @TdHHUnits As int OUTPUT, @TdHH Decimal(9,2) OUTPUT, @TdPerm Decimal(9,2) OUTPUT, @TdTotal int OUTPUT ) AS SELECT @TdPermUnits = TP_TOTAL, @TdHHUnits = THH_TOTAL FROM TOWN WHERE Town = @Town SELECT @TdTotal = @TdPermUnits + @TdHHUnits SELECT @TdPerm = 100.00 * @TdPermUnits / @TdTotal SELECT @TdHH = 100.00 * @TdHHUnits / @TdTotal GO Here is my asp.net application: oCmd = New SqlCommand("sproc_GetTown", oConn) oCmd.CommandType = Data.CommandType.StoredProcedure oParam = oCmd.Parameters.Add("@Town", Data.SqlDbType.VarChar, 100) oParam.Direction = Data.ParameterDirection.Input oParam.Value = Townland oParam = oCmd.Parameters.Add("@TdHH", Data.SqlDbType.Decimal, 9, 2) oParam.Direction = Data.ParameterDirection.Output oParam = oCmd.Parameters.Add("@TdPerm", Data.SqlDbType.Decimal, 9, 2) oParam.Direction = Data.ParameterDirection.Output oParam = oCmd.Parameters.Add("@TdHHUnits", Data.SqlDbType.Int, 4) oParam.Direction = Data.ParameterDirection.Output oParam = oCmd.Parameters.Add("@TdPermUnits", Data.SqlDbType.Int, 4) oParam.Direction = Data.ParameterDirection.Output oParam = oCmd.Parameters.Add("@TdTotal", Data.SqlDbType.Int, 4) oParam.Direction = Data.ParameterDirection.Output oConn.Open() oCmd.ExecuteNonQuery() oConn.Close() Dim ldcTDHH As Decimal ldcTDHH = oCmd.Parameters("@TdHH").Value The value in ldcTDHH is always rounded off to the nearest whole number. Anyone know whats wrong? macca
-
Decimals problem. I have a stored procedure that returns values as decimals if I run it on query analyzer. The problem I have is that when the value is passed to my asp.net application the decimal places disappear and the values are rounded to the nearest whole number. Here is my stored procedure: CREATE PROCEDURE sproc_GetTown ( @Town varchar(100), @TdPermUnits As int OUTPUT, @TdHHUnits As int OUTPUT, @TdHH Decimal(9,2) OUTPUT, @TdPerm Decimal(9,2) OUTPUT, @TdTotal int OUTPUT ) AS SELECT @TdPermUnits = TP_TOTAL, @TdHHUnits = THH_TOTAL FROM TOWN WHERE Town = @Town SELECT @TdTotal = @TdPermUnits + @TdHHUnits SELECT @TdPerm = 100.00 * @TdPermUnits / @TdTotal SELECT @TdHH = 100.00 * @TdHHUnits / @TdTotal GO Here is my asp.net application: oCmd = New SqlCommand("sproc_GetTown", oConn) oCmd.CommandType = Data.CommandType.StoredProcedure oParam = oCmd.Parameters.Add("@Town", Data.SqlDbType.VarChar, 100) oParam.Direction = Data.ParameterDirection.Input oParam.Value = Townland oParam = oCmd.Parameters.Add("@TdHH", Data.SqlDbType.Decimal, 9, 2) oParam.Direction = Data.ParameterDirection.Output oParam = oCmd.Parameters.Add("@TdPerm", Data.SqlDbType.Decimal, 9, 2) oParam.Direction = Data.ParameterDirection.Output oParam = oCmd.Parameters.Add("@TdHHUnits", Data.SqlDbType.Int, 4) oParam.Direction = Data.ParameterDirection.Output oParam = oCmd.Parameters.Add("@TdPermUnits", Data.SqlDbType.Int, 4) oParam.Direction = Data.ParameterDirection.Output oParam = oCmd.Parameters.Add("@TdTotal", Data.SqlDbType.Int, 4) oParam.Direction = Data.ParameterDirection.Output oConn.Open() oCmd.ExecuteNonQuery() oConn.Close() Dim ldcTDHH As Decimal ldcTDHH = oCmd.Parameters("@TdHH").Value The value in ldcTDHH is always rounded off to the nearest whole number. Anyone know whats wrong? macca
-
apply the value to a string in the code behind then convert to a decimal in code behind, this might help
-
Decimals problem. I have a stored procedure that returns values as decimals if I run it on query analyzer. The problem I have is that when the value is passed to my asp.net application the decimal places disappear and the values are rounded to the nearest whole number. Here is my stored procedure: CREATE PROCEDURE sproc_GetTown ( @Town varchar(100), @TdPermUnits As int OUTPUT, @TdHHUnits As int OUTPUT, @TdHH Decimal(9,2) OUTPUT, @TdPerm Decimal(9,2) OUTPUT, @TdTotal int OUTPUT ) AS SELECT @TdPermUnits = TP_TOTAL, @TdHHUnits = THH_TOTAL FROM TOWN WHERE Town = @Town SELECT @TdTotal = @TdPermUnits + @TdHHUnits SELECT @TdPerm = 100.00 * @TdPermUnits / @TdTotal SELECT @TdHH = 100.00 * @TdHHUnits / @TdTotal GO Here is my asp.net application: oCmd = New SqlCommand("sproc_GetTown", oConn) oCmd.CommandType = Data.CommandType.StoredProcedure oParam = oCmd.Parameters.Add("@Town", Data.SqlDbType.VarChar, 100) oParam.Direction = Data.ParameterDirection.Input oParam.Value = Townland oParam = oCmd.Parameters.Add("@TdHH", Data.SqlDbType.Decimal, 9, 2) oParam.Direction = Data.ParameterDirection.Output oParam = oCmd.Parameters.Add("@TdPerm", Data.SqlDbType.Decimal, 9, 2) oParam.Direction = Data.ParameterDirection.Output oParam = oCmd.Parameters.Add("@TdHHUnits", Data.SqlDbType.Int, 4) oParam.Direction = Data.ParameterDirection.Output oParam = oCmd.Parameters.Add("@TdPermUnits", Data.SqlDbType.Int, 4) oParam.Direction = Data.ParameterDirection.Output oParam = oCmd.Parameters.Add("@TdTotal", Data.SqlDbType.Int, 4) oParam.Direction = Data.ParameterDirection.Output oConn.Open() oCmd.ExecuteNonQuery() oConn.Close() Dim ldcTDHH As Decimal ldcTDHH = oCmd.Parameters("@TdHH").Value The value in ldcTDHH is always rounded off to the nearest whole number. Anyone know whats wrong? macca
-
Decimals problem. I have a stored procedure that returns values as decimals if I run it on query analyzer. The problem I have is that when the value is passed to my asp.net application the decimal places disappear and the values are rounded to the nearest whole number. Here is my stored procedure: CREATE PROCEDURE sproc_GetTown ( @Town varchar(100), @TdPermUnits As int OUTPUT, @TdHHUnits As int OUTPUT, @TdHH Decimal(9,2) OUTPUT, @TdPerm Decimal(9,2) OUTPUT, @TdTotal int OUTPUT ) AS SELECT @TdPermUnits = TP_TOTAL, @TdHHUnits = THH_TOTAL FROM TOWN WHERE Town = @Town SELECT @TdTotal = @TdPermUnits + @TdHHUnits SELECT @TdPerm = 100.00 * @TdPermUnits / @TdTotal SELECT @TdHH = 100.00 * @TdHHUnits / @TdTotal GO Here is my asp.net application: oCmd = New SqlCommand("sproc_GetTown", oConn) oCmd.CommandType = Data.CommandType.StoredProcedure oParam = oCmd.Parameters.Add("@Town", Data.SqlDbType.VarChar, 100) oParam.Direction = Data.ParameterDirection.Input oParam.Value = Townland oParam = oCmd.Parameters.Add("@TdHH", Data.SqlDbType.Decimal, 9, 2) oParam.Direction = Data.ParameterDirection.Output oParam = oCmd.Parameters.Add("@TdPerm", Data.SqlDbType.Decimal, 9, 2) oParam.Direction = Data.ParameterDirection.Output oParam = oCmd.Parameters.Add("@TdHHUnits", Data.SqlDbType.Int, 4) oParam.Direction = Data.ParameterDirection.Output oParam = oCmd.Parameters.Add("@TdPermUnits", Data.SqlDbType.Int, 4) oParam.Direction = Data.ParameterDirection.Output oParam = oCmd.Parameters.Add("@TdTotal", Data.SqlDbType.Int, 4) oParam.Direction = Data.ParameterDirection.Output oConn.Open() oCmd.ExecuteNonQuery() oConn.Close() Dim ldcTDHH As Decimal ldcTDHH = oCmd.Parameters("@TdHH").Value The value in ldcTDHH is always rounded off to the nearest whole number. Anyone know whats wrong? macca
Try by splitting the decimal value in 2 strings and passing with concatenation, don't forget to add "." in between. If DBMS is SQL Server 2005, it will work...the problem is due to different ways .NET and SQL Server 2005 stores the decimal value. HTH
Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.