I'm trying to retrieve an amount from SQL.
I have a table tbVendas with a column ValorTotalVendas of datatype DECIMAL.
I have the following select query
SELECT IdVendas AS 'Venda'
FROM tbVendas
WHERE ValorTotalVendas = '@valorTotal'
And below my command
SqlCommand comando = new SqlCommand(strSql, conn);
comando.Parameters.Add("@valorTotal", SqlDbType.Decimal);
comando.Parameters["@valorTotal"].Value = Convert.ToDecimal(txbValorFiltro.Text);
DataTable vendas = new DataTable();
conn.Open();
SqlDataAdapter sqdDA = new SqlDataAdapter(strSql, conn);
sqdDA.Fill(vendas);
But I get this error:
Error converting datatype varchar to numeric
Can anyone please help me?
txbValorFiltro.Textand what's the decimal separator in your Operative System?SELECT IdVendas AS 'Venda' FROM tbVendas WHERE ValorTotalVendas = @valorTotal. Otherwise, it sees it as the string instead of seeing it as a parameter name.