tags:

views:

208

answers:

1
try
{
    int val4 = Convert.ToInt32(tbGrupa.Text);
    string MyConString = "Data Source=**;User ID=******;Password=*****";
    OracleConnection conexiune = new OracleConnection(MyConString);
    OracleCommand comanda = new OracleCommand();
    comanda.Connection = conexiune;
    conexiune.Open();
    comanda.Transaction = conexiune.BeginTransaction();
    int id_stud = Convert.ToInt16(tbCodStud.Text);
    string nume = tbNume.Text;
    string prenume = tbPrenume.Text;
    string initiala_tatalui = tbInitiala.Text;
    string email = tbEmail.Text;
    string facultate = tbFac.Text;
    int grupa = Convert.ToInt16(tbGrupa.Text);
    string serie = tbSeria.Text;
    string forma_de_inv = tbFormaInvatamant.Text;
    DateTime data_acceptare_coordonare = dateTimePicker1.Value;
    DateTime data_sustinere_licenta = dateTimePicker2.Value;
    string sustinere = tbSustinereLicenta.Text;
    string parola_acces = tbParola.Text;

    try
    {
        comanda.Parameters.AddWithValue("id_stud", id_stud);
        comanda.Parameters.AddWithValue("nume", nume);
        comanda.Parameters.AddWithValue("prenume", prenume);
        comanda.Parameters.AddWithValue("initiala_tatalui", initiala_tatalui);
        comanda.Parameters.AddWithValue("facultate", facultate);
        comanda.Parameters.AddWithValue("email", email);
        comanda.Parameters.AddWithValue("seria", serie);
        comanda.Parameters.AddWithValue("grupa", grupa);
        comanda.Parameters.AddWithValue("forma_de_inv", forma_de_inv);
        comanda.Parameters.AddWithValue("data_acceptare_coordonare", data_acceptare_coordonare);
        comanda.Parameters.AddWithValue("data_sustinere_licenta", data_sustinere_licenta);
        comanda.Parameters.AddWithValue("sustinere_licenta", sustinere);
        comanda.Parameters.AddWithValue("parola_acces", parola_acces);

        comanda.Transaction.Commit();
        MessageBox.Show("Studentul " + tbNume.Text + " " + tbPrenume.Text + " a fost adăugat în baza de date!");
    }
    catch (Exception er)
    {
        comanda.Transaction.Rollback();
        MessageBox.Show("ER1.1:" + er.Message);
        MessageBox.Show("ER1.2:" + er.StackTrace);
    }
    finally
    {
        conexiune.Close();
    }
}
catch (Exception ex)
{
    MessageBox.Show("ER2.1:"+ex.Message);
    MessageBox.Show("ER2.2:"+ex.StackTrace);
}
+2  A: 

There doesn't seem to be an insert statement. I think this is what the problem is. You would need some thing like:

using (OracleConnection connection = new OracleConnection(connectionString))
{
    OracleCommand command = new OracleCommand(myExecuteQuery, connection);
    command.Connection.Open();
    command.ExecuteNonQuery();
}

There's a commit statement, what what are you going to commit if there's no insert statement prior to that?

Khnle
so..i missed the insert statement..but it does the same thing: the only thing that it shows to me is that Student X Y was inserted in the db but it doesn't really insert it actually.. This is what i missed but still non-working: comanda.CommandText = "INSERT INTO student VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)"; comanda.Parameters.AddWithValue("id_stud", id_stud); comanda.Parameters.AddWithValue("nume", nume); comanda.Parameters.AddWithValue("prenume", prenume); [...] [by the way it's in romanian]
Gya