-1
I have a datagridview that is filled as soon as I choose the items that in the case are products that contain quantity in the product insert I choose a quantity and add the item to datagridview, after finalizing the purchase I am not getting the low in that quantity. I created an update but only updates the last product added to datagridview. I am using the code below to update the product quantity.
public void baixaEstoque()
{
//..
string strCon = "Data Source = DESKTOP-MBLAUPI\\SQLEXPRESS; Initial Catalog = db_controle_loja; Integrated Security = True";
SqlConnection conexao = new SqlConnection(strCon);
//..
SqlCommand cmd = new SqlCommand(" update dbo.tb_produto set quantidade = quantidade - " + quantidadeTextBox.Text +
" where id_produto = @id_produto", conexao);
cmd.Parameters.Add("@id_produto", SqlDbType.Int).Value = codigoTextBox.Text;
cmd.Parameters.Add("@quantidadeTextBox", SqlDbType.Int).Value = quantidadeTextBox.Text;
try
{
conexao.Open();
cmd.ExecuteScalar();
//..
}
catch (Exception ex)
{
MessageBox.Show("Erro " + ex.Message);
throw;
}
finally
{
conexao.Close();
}
}
After entering the item in the sale you store your items where? In a class? Or you just enter the data in the
gridview
?– Matheus Ribeiro
insert only in gridview.
– Ricardo luiz
I have to go through the gridview on each item added and change the amount in the database my code is only worked for one item in case when add two items it change only the amount of the last of my gridview.
– Ricardo luiz