Why I cannot update my record on my database. I receive this message (not saved). Please have a look on my codes to see if somethink is wrong.
private void btnUpdate_ProdutoStock_Click(object sender, EventArgs e)
{
{
conn = new SqlConnection(connstr);
comm = new SqlCommand();
conn.Open();
SqlParameter code = new SqlParameter("@cod", SqlDbType.VarChar);
SqlParameter product = new SqlParameter("@prod", SqlDbType.NChar);
SqlParameter price = new SqlParameter("@price", SqlDbType.NChar);
SqlParameter n_stock = new SqlParameter("@stock", SqlDbType.NChar);
comm.Parameters.Add(code );
comm.Parameters.Add(product );
comm.Parameters.Add(price );
comm.Parameters.Add(n_stock);
code .Value = codigoBarraStocks.Text;
product .Value = produtoStocks.Text;
price .Value = precoStocks.Text;
n_stock.Value = nStocksStocks.Text;
comm.Connection = conn;
comm.CommandText ="UPDATE consult SET code = @cod, product= @prod, price = @preco, n_stock= @stock WHERE (code = @cod)";
try
{
comm.ExecuteNonQuery();
MessageBox.Show("Saved");
}
catch (Exception)
{
MessageBox.Show("Not saved");
}
finally
{
conn.Close();
}
}
}
}
}