1
I’m new to C# and I’m taking a beating to record texbox data in SQL Server
private void Btn_salvar_Click(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection(strConexao))
{
string sql = @"insert into tb_Produtos (descprod, ean, precovenda, precocusto, codforn) values
(@DPROD,@EAN,@PRECO,@CUSTO,@FORN)";
con.Open();
using (SqlCommand cmd = new SqlCommand(sql, con))
{
cmd.Parameters.Add("@DPROD",SqlDbType.VarChar).Value=txtdesc;
cmd.Parameters.Add("@EAN",SqlDbType.VarChar).Value=txtean.Text;
cmd.Parameters.Add("@PRECO", SqlDbType.Float).Value = txtpreco.Text;
cmd.Parameters.Add("@CUSTO",SqlDbType.VarChar).Value= txtprecusto.Text;
cmd.Parameters.Add("@FORN",SqlDbType.Int).Value=cbfor.Text;
int retorno = cmd.ExecuteNonQuery();
if (retorno == 1)
{
MessageBox.Show("Produto Gravado com sucesso!");
}
else
{
MessageBox.Show("Erro ao gravar.");
}
}
}
that txtdesc there shouldn’t be with. text either?
– Lucas Miranda