将数据类型nvarchar转换为十进制时出错的解决方案 [英] Solution for Error converting data type nvarchar to decimal

查看:98
本文介绍了将数据类型nvarchar转换为十进制时出错的解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于将数据类型nvarchar转换为十进制的问题,在我更新这些信息的过程中,我的解决方案在转换错误时中断。所以这是我的代码:



I have a question about converting data type nvarchar to decimal, in a procedure when i update those informations my solution break in a error about converting. So this is my code:

objGrupoCadCom.CusteioSegurado = decimal.Parse(txtCusteioSegurado.Text);
objGrupoCadCom.CusteioEstipulante = decimal.Parse(txtCusteioEstipulante.Text);
objGrupoCadCom.ProLabore = decimal.Parse(txtProLabore.Text);





这是我的错误:





and this is my error:

"Erro ao Alterar Cadastro Grupo Complementar: Error converting data type nvarchar to decimal." 





有谁知道我如何解决这个错误?我使用C#和Aspx来做这个解决方案。

谢谢。



我的程序:



所以,这是我的程序。





Anybody know how i fix this error ?? I use C# and Aspx to do this solution.
Thanks.

My Procedure:

So, this is my Procedure.

-----------------------------------------------------------------------------------
CREATE PROCEDURE VEW_GrupoCadastroComplementar_Alterar  (
	@IdGrupo int	
	, @IdRamoAtividade int
	, @Endereco varchar(60)
	, @Numero varchar(8)
	, @CEP varchar(9)
	, @Complemento varchar(60)
	, @Bairro varchar(30)
	, @Cidade varchar(30)
	, @UF varchar(2)
	, @DDD varchar(4)
	, @Telefone varchar(9)
	, @SituacaoFinanceira varchar(20)
	, @ComplementoGrupoLivre varchar(max)
	, @CusteioSeguro varchar(20)
	, @PagamentoPremio varchar(20)
	, @CusteioEstipulante decimal(10,2)
	, @CusteioSegurado decimal(10,2)
	, @ProLabore decimal(10,2)
	, @ProLaboreDocumento varchar(3)
) 
AS 
SET NOCOUNT ON 

UPDATE VEW_Grupo
SET 
	IdRamoAtividade = @IdRamoAtividade
	, Endereco = @Endereco
	, Numero = @Numero
	, CEP = @CEP
	, Complemento = @Complemento
	, Bairro = @Bairro
	, Cidade = @Cidade
	, UF = @UF
	, DDD = @DDD
	, Telefone = @Telefone
	, SituacaoFinanceira = @SituacaoFinanceira
	, ComplementoGrupoLivre = @ComplementoGrupoLivre
	, CusteioSeguro = @CusteioSeguro
	, PagamentoPremio = @PagamentoPremio
	, CusteioEstipulante = @CusteioEstipulante
	, CusteioSegurado = @CusteioSegurado
	, ProLabore = @ProLabore
	, ProLaboreDocumento = @ProLaboreDocumento
WHERE 
	idGrupo = @idGrupo

SET NOCOUNT OFF



WHERE
	idGrupo = @idGrupo

SET NOCOUNT OFF

推荐答案

在这种情况下,你应该总是使用 Decimal.TryParse方法 [ ^ ]。

请参阅示例: C#Decimal TryParse (字符串,十进制) [ ^ ]。



- Amy
In that case you should always use Decimal.TryParse Method[^].
See the example : C# Decimal TryParse(String, Decimal)[^].

--Amy


Quote:

objGrupoCadCom.CusteioSegurado = decimal.Parse(txtCusteioSegurado.Text);



之后我的尝试捕获 转到消息错误。报告消息 - > Erro ao Alterar Cadastro Grupo Complementar:将数据类型nvarchar转换为十进制时出错。

objGrupoCadCom.CusteioSegurado = decimal.Parse(txtCusteioSegurado.Text);

after this my "try catch" go to the Message Error. Reporting the message -> "Erro ao Alterar Cadastro Grupo Complementar: Error converting data type nvarchar to decimal."

因此文本框值不是十进制值。因此解析失败。



要知道是否可以解析该值,请使用decimal.tryparse使用out参数。

So the text box value is not a decimal value. Thus the parsing is failed.

To know whether the value can be parsed, use decimal.tryparse the use the out parameter.


这篇关于将数据类型nvarchar转换为十进制时出错的解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆