如下,从数据库的存储过程传值过去给C#,如果不再转换一次,C#接收到的值就会有问题,我原来传了一个17800.15,c#中接收到成了17800.156,怎么搞都不对。
ActualAmount数据库中定义的是decimal(18,2)
数据库中
代码中
后来改成解决
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
-------------------------------------------------------------------------------------
本文讨论了在使用C#调用数据库存储过程时遇到的值传递问题,特别是涉及到数值类型转换的问题。通过修改存储过程的查询语句,确保C#接收的数据与数据库存储一致,避免了值传递错误。
1052

被折叠的 条评论
为什么被折叠?



