I have an insert that receives some parameters, but at the moment that the sql statement is giving this conversion error:
Error converting data type varchar to numeric.
//http://localhost:7630/api/AspNetWebApi/cadastrar/jogo/4512/20.01/20.10/5
[HttpPost]
[Route("cadastrar/jogo/{nJogo}/{valor}/{total}/{idusuario}")]
public HttpResponseMessage Cadastro(int nJogo, decimal valor, decimal total, int idusuario)
{
try
{
var tTabela = new JogoDetalheAplicacao();
tTabela.Inseri(nJogo, valor,total,idusuario);
return Request.CreateResponse(HttpStatusCode.OK, "Cadastro realizado.");
}
catch (Exception ex)
{
return Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
}
}
public void Inseri(int nJogo, decimal valor, decimal total, int idusuario)
{
var strQuery = "";
strQuery += "INSERT INTO TB_JOGO_DETALHE_TEMP (NUMERO_JOGO, VALOR_JOGO,VALOR_TOTAL,IDUSUARIO)";
strQuery += string.Format(" VALUES (");
strQuery += string.Format(" {0}, ", nJogo);
strQuery += string.Format(CultureInfo.InvariantCulture, " {0:0.00}, ", valor);
strQuery += string.Format(CultureInfo.InvariantCulture, " {0:0.00}, ", total);
strQuery += string.Format(" {0} ", idusuario);
strQuery += string.Format(" ) ");
using (contexto = new Contexto())
{
contexto.ExecutaComando(strQuery);
}
}
Result of the final sql query:
INSERT INTO TB_JOGO_DETALHE_TEMP (NUMERO_JOGO, VALOR_JOGO,VALOR_TOTAL,IDUSUARIO) VALUES ('4512','20,01','20,10','5' )
The correct thing would be to look like this:
INSERT INTO TB_JOGO_DETALHE_TEMP (NUMERO_JOGO, VALOR_JOGO,VALOR_TOTAL,IDUSUARIO) VALUES ('4512',20.01,20.10,'5' )