Insert error ... Values using oracle error 00936

Asked

Viewed 48 times

0

I’m trying to make an Insert on a table and it’s always giving me error 00936 that says Missing Expression when you arrive at the command line cmd.executenonquery. Can anyone help me? Code 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 lies in the execution of the line of executenonquery. Can anyone tell me what I’m forgetting? Thank you. I have a table with 6 columns where one of them is the primary key (ID). Help me...

  • You have already tried to add Insert 'entreosParametros'?

2 answers

0

It would look something 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
;

0

Good Afternoon, my brother.

It seems you are passing five values per parameter, and there are six fields to be filled. Pass the id value in INSERT or create a Sequence for it. The error says there is a field being omitted and it is required to be filled in, which in case is the key Primary.

  • ola mano @Luccas Ramos. How do I do this to create a sequence for id?

  • Follow the script as it would look, more or less.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.