数据库中的数据到C#代码中的数值要注意转换了

如下,从数据库的存储过程传值过去给C#,如果不再转换一次,C#接收到的值就会有问题,我原来传了一个17800.15,c#中接收到成了17800.156,怎么搞都不对。
ActualAmount数据库中定义的是decimal(18,2)

数据库中

ALTER PROCEDURE [dbo].[P_Sys_GetCFPGStageSum]
-- Add the parameters for the stored procedure here
--@CompanyID nvarchar(50),
--@ContractID nvarchar(50),
@OrderID nvarchar(50)
--@StageId nvarchar(50),
--@StageAmount numeric(18,2),
--@BFB nvarchar(50),
--@Playtime DATETIME,
-- @StageDes nvarchar(150),
----@GotAmount numeric(18,2),--已收
--@CurrentAmount numeric(18,2),--当前收款
--@CreatedByUserID nvarchar(50),
--@WBSID nvarchar(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
select ISNULL(SUM(ActualAmount),0) from [T_SaleConfirmStage]
where OrderID =@OrderID and IsDeleted=0
END



END

代码中

public float GetCFPGStageSum(string DDH)
{
float iResult = 0;
using (IDataContext ctx = DataContext.Instance())
{
iResult = ctx.ExecuteScalar<float>(System.Data.CommandType.StoredProcedure,
"[P_Sys_GetCFPGStageSum]", DDH);
}
return iResult;
}


后来改成解决


ALTER PROCEDURE [dbo].[P_Sys_GetCFPGStageSum]
-- Add the parameters for the stored procedure here
--@CompanyID nvarchar(50),
--@ContractID nvarchar(50),
@OrderID nvarchar(50)
--@StageId nvarchar(50),
--@StageAmount numeric(18,2),
--@BFB nvarchar(50),
--@Playtime DATETIME,
-- @StageDes nvarchar(150),
----@GotAmount numeric(18,2),--已收
--@CurrentAmount numeric(18,2),--当前收款
--@CreatedByUserID nvarchar(50),
--@WBSID nvarchar(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
--rzp20150126------------------------------------------------------------------------
--select ISNULL(SUM(ActualAmount),0) from [T_SaleConfirmStage]
--where OrderID =@OrderID and IsDeleted=0

select CONVERT(DECIMAL(18,2), ISNULL(SUM(ActualAmount),0)) from [T_SaleConfirmStage]
where OrderID =@OrderID and IsDeleted=0
-------------------------------------------------------------------------------------

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值