Пример #1
0
        private void ModificaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AdaugaProd ap = new AdaugaProd((Produse)listView1.SelectedItems[0].Tag);

            ap.ShowDialog();

            if (ap.DialogResult == DialogResult.OK)
            {
                OleDbConnection conexiune = new OleDbConnection(Provider);
                OleDbCommand    comanda   = new OleDbCommand();
                comanda.Connection = conexiune;
                try
                {
                    conexiune.Open();
                    comanda.Transaction = conexiune.BeginTransaction();
                    comanda.CommandText = " update produs set pret=@pret, " + "  cantitate=@cantitate  where nume=@nume";

                    comanda.Parameters.Add("pret", OleDbType.Double).Value       = ap.a.Pret;
                    comanda.Parameters.Add("cantitate", OleDbType.Integer).Value = ap.a.Cantitate;
                    comanda.Parameters.Add("nume", OleDbType.Char).Value         = ap.a.Nume;
                    comanda.ExecuteScalar();
                    comanda.Transaction.Commit();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    comanda.Transaction.Rollback();
                }
                finally
                {
                    conexiune.Close();
                }
                UpdateList();
            }
        }
Пример #2
0
        private void AdaugaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AdaugaProd f2 = new AdaugaProd();

            f2.ShowDialog();
            if (f2.DialogResult == DialogResult.OK)
            {
                OleDbConnection conexiune = new OleDbConnection(Provider);
                OleDbCommand    comanda   = new OleDbCommand();
                comanda.Connection = conexiune;
                try
                {
                    conexiune.Open();
                    comanda.Transaction = conexiune.BeginTransaction();


                    comanda.CommandText = "INSERT INTO produs(nume, pret,cantitate)" + "VALUES( @nume,@pret,@cantitate)";

                    comanda.Parameters.Add("nume", OleDbType.Char).Value         = f2.a.Nume;//putem pune si exceptie gen de 10 caractere dupa , Add("nume", OleDbType.Char,10)
                    comanda.Parameters.Add("pret", OleDbType.Double).Value       = f2.a.Pret;
                    comanda.Parameters.Add("cantitate", OleDbType.Integer).Value = f2.a.Cantitate;



                    comanda.ExecuteNonQuery();
                    comanda.Transaction.Commit();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    comanda.Transaction.Rollback();
                }
                finally
                {
                    conexiune.Close();
                }
                UpdateList();
            }
        }