Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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:

C#
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." 


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

My Procedure:

So, this is my Procedure.

SQL
-----------------------------------------------------------------------------------
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
Posted
Updated 20-Oct-15 1:17am
v3
Comments
ZurdoDev 19-Oct-15 13:28pm    
That means whatever the nvarchar values is, it is not a number. It could be a blank or a letter or something else.

This is such an easy thing for you to fix if you debug it.
Richard Deeming 19-Oct-15 13:29pm    
The error message you've posted is being generated by SQL code. The code you've posted has nothing to do with the error.
Suvendu Shekhar Giri 19-Oct-15 13:31pm    
true :)
Nicholas Guaratini 20-Oct-15 7:13am    
So , you advises what in my SQL Code ??
Some type change ? like varchar ? numeric ? Any idea ?
Richard Deeming 20-Oct-15 8:30am    
You have a data-type mismatch somewhere in your database. You haven't shown the definition of the VEW_Grupo table, so we can't tell you where it is.

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

--Amy
 
Share this answer
 
Quote:
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."
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900