Torna al Thread

using (SqlConnection conn = new SqlConnection(MainForm.Database())) { conn.Open(); query = "SELECT articoli.id, prodotti_acquistati.quantita FROM articoli, prodotti_acquistati WHERE prodotti_acquistati.id_acquisto=" + System.Convert.ToInt64(dataGridView1.CurrentRow.Cells[0].Value) + " AND articoli.codice=prodotti_acquistati.codice AND prodotti_acquistati.conta=1"; oleCmd = new SqlCommand(); oleCmd.Connection = conn; oleCmd.Transaction = trans; oleCmd.CommandText = query; SqlDataReader reader = oleCmd.ExecuteReader(); while (reader.Read()) { string queryUP = "UPDATE giacenze SET quantita = quantita - " + reader[1].ToString() + " WHERE id=" + reader[0].ToString(); SqlCommand oleCmdUP = new SqlCommand(); oleCmdUP.Connection = conn; oleCmdUP.Transaction = trans; oleCmdUP.CommandText = queryUP; oleCmdUP.ExecuteNonQuery(); // Al comando è già associato un DataReader aperto, che deve essere chiuso. } reader.Close(); } catch (SqlException ex) { trans.Rollback(); MessageBox.Show("Si sono verificati degli errori nella rimozione della fattura, operazione annullata... " + ex.ToString()); } finally { conn.Close(); } }
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5