Why is the dot replaced by a comma when sending the c# Sqlcommand to the database?

Asked

Viewed 39 times

-2

inserir a descrição da imagem aqui

Note that in the first image the value is still correct: 150.45 The problem is that when sending the command to the database the point is replaced by comma, in the second image I captured the command by SQL Server Profiler and we can notice that the point was actually replaced by comma. How can I fix this?

inserir a descrição da imagem aqui

1 answer

0

I just figured out how to solve the problem, I’ll share here maybe help someone else.

var cmdText = ($@"INSERT INTO PESSOASERVICOPRESTADO (CODPESSOA, DESCRICAOSERVICO, 
VALORTOTAL, VALORPAGO, PAGO, DATASERVICO ) VALUES ({servico.CodPessoa}, 
'{servico.DescricaoServico}', 
{servico.ValorTotal.ToString(CultureInfo.InvariantCulture)}, 
{servico.ValorPago.ToString(CultureInfo.InvariantCulture)}, '{servico.Pago}' 
,'{servico.DataServico}')");

Just add the following code to the Sql command: ToString(CultureInfo.InvariantCulture), so Sql server ignores the region setting and sends the statement with the dot instead of the comma that would cause trouble.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.