简体   繁体   中英

Cannot insert into oracle using .net (ORA 00911 error)

So, I'm building a C# application, using .NET and oracle 11g express. I've already connected to the database, but, for some reason, it cannot insert into the database, it keeps giving the ORA 00911 error. This is the code:

    private void toolStripButton1_Click(object sender, EventArgs e)
    {
        string salvar;           
        dbConnection conn = new dbConnection();
        try
        {
            conn.tryconection();
            salvar = "INSERT INTO Client(Name, Document, City, Contact, Addr, District, Zipcode, Phone_1, Phone_2, Cel_1, Cel_2, eymael, tobar) VALUES('" + boxNome.Text + "', '" + boxDocumento.Text + "','" + boxCidade.Text + "','" + boxContato.Text + "','" + boxEndereco.Text + "','" + boxBairro.Text + "','" + boxCep.Text + "','" + boxFone1.Text + "','" + boxFone2.Text + "','" + boxCel1.Text + "','" + boxCel2.Text + "','" + boxEmail.Text + "','" + boxComment.Text + "');";
            //MessageBox.Show(salvar);
            conn.executaInstrucao(salvar);
            //conn.executaInstrucao("commit;");
        }
        catch (Exception g)
        {
            MessageBox.Show("Problema na conexão");
        }

    }

This is the output string with some random values, wich works on SQL Developer and actually adds the row:

INSERT INTO Client(Name, Document, City, Contact, Addr, District, Zipcode, Phone_1, Phone_2, Cel_1, Cel_2, eymael, tobar) VALUES('asdassdsad', '15.465.465/4654-54','654654654','654654654','654654654','654654654','65465-465','(65) 4654-6546','(54) 6546-5465','(46) 54654-6546','(65) 46546-5465','4654654654','65465465465');

Someone help me, please. I have no idea of what is wrong.

PS.: All my columns are VARCHAR2.

ORA 00911 is invalid char problem. If you have ' char in your textboxes, may be it makes problem. Like comment above use SqlCommand.Parameters.AddWithValue like Soner Gönül said parameter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM