Error in Insert ... Values using oracle error 00936

0

I'm trying to make an insert into a table and it always gives me the error 00936 that says missing expression when it arrives at the cmd.executenonquery command line. Can someone help me? Code that I have:

using (OracleConnection conn = new OracleConnection(ConfigurationManager
                   .ConnectionStrings["CegosReportsOra"].ConnectionString))
    {
        conn.Open();

        using (OracleCommand cmd = new OracleCommand())

        {

            String lang = System.Threading.Thread.CurrentThread.CurrentUICulture.ToString();
            lang = "";
            cmd.CommandType = CommandType.Text;
            cmd.Connection = conn;
            cmd.CommandText = "INSERT INTO ECICalendarEvent_Test(title, description, event_start, event_end, all_day) Values(@title, @description, @event_start, @event_end, @all_day)";

            cmd.Parameters.Add("@title", OracleDbType.Varchar2).Value = cevent.title;
            cmd.Parameters.Add("@description", OracleDbType.Varchar2).Value = cevent.description;
            cmd.Parameters.Add("@event_start", OracleDbType.Date).Value = cevent.start;
            cmd.Parameters.Add("@event_end", OracleDbType.Date).Value = cevent.end;
            cmd.Parameters.Add("@all_day", OracleDbType.Char).Value = cevent.allDay;
            cmd.ExecuteNonQuery();
            int key = 0;
            using (conn)
            {



                //get primary key of inserted row
                cmd.CommandText = "SELECT max(event_id) FROM ECICalendarEvent_Test where title=@title AND description=@description AND event_start=@event_start AND event_end=@event_end AND all_day=@all_day";
                cmd.Parameters.Add("@title", OracleDbType.Varchar2).Value = cevent.title;
                cmd.Parameters.Add("@description", OracleDbType.Varchar2).Value = cevent.description;
                cmd.Parameters.Add("@event_start", OracleDbType.Date).Value = cevent.start;
                cmd.Parameters.Add("@event_end", OracleDbType.Date).Value = cevent.end;
                cmd.Parameters.Add("@all_day", OracleDbType.Char).Value = cevent.allDay;

                key = (int)cmd.ExecuteScalar();
            }

            return key;
        }

The problem is with running the executenonquery line. Can anyone tell me what I'm forgetting? Thank you. I have a table with 6 columns in which one of them is the primary key (ID). Help me ...

    
asked by anonymous 26.04.2016 / 19:08

2 answers

0
Good afternoon, bro.

It looks like you're passing five values per parameter, and there are six fields to fill out. Pass the value of the id in the INSERT or create a Sequence for it. The error says there is a field being omitted and that is required to be filled, which in the case is the primary key.

    
26.04.2016 / 19:31
0

It would look more or less like this.

INSERT INTO ECICalendarEvent_Test(seu_id,title, description, event_start, event_end, all_day) Values(nome_sequence.NEXTVAL,@title, @description, @event_start, @event_end, @all_day)";

--Crie a sequence no banco ... 
CREATE SEQUENCE nome_sequence
 START WITH     1 -- Valor em que a sequence vai iniciar 
 INCREMENT BY   1 -- de quanto em quanto será incrementado
;
    
27.04.2016 / 14:34