Search code examples
c#asp.netoraclevisual-studio-2010odp.net

Missing SELECT keyword when inserting in ASP.NET


I am completely blind with this Error. I'm more of a Java man than an ASP one. So here is my code and my question :

Here is my code that produce the error :

protected void ButtonOk_Click(object sender, EventArgs e)
    {
       // OracleConnection connect = new OracleConnection();
       // connect.ConnectionString = ConfigurationManager.ConnectionStrings["Absensi2.Properties.Settings.Setting"].ConnectionString;
       //// SqlConnection connect = new SqlConnection(getConnection());
        var sql = "insert into master_dosen('NIP','NAMA_DOSEN','KETERANGAN') values (:NIP, :NAMA_DOSEN, :KETERANGAN)";

        using (OracleConnection c = new OracleConnection(ConfigurationManager.ConnectionStrings["Absensi2.Properties.Settings.Setting"].ConnectionString))
        {
            c.Open();
            using (OracleCommand cmd = new OracleCommand(sql, c))
            {
                cmd.Parameters.Add(":NIP", TextBoxNIP.Text);
                cmd.Parameters.Add(":NAMA_DOSEN", TextBoxNamaDosen.Text);
                cmd.Parameters.Add(":KETERANGAN", TextBoxKeterangan.Text);

                cmd.ExecuteNonQuery();
                GridView1.DataBind();
            }
            c.Close();
        }

The error is : ORA-00928: missing SELECT keyword in line cmd.ExecuteNonQuery();

Missing SELECT

I already search and it says deprecated. is it true?

NB : I am using ODP.NET, and I am using visual studio 2010.


Solution

  • The problem with your query is that you are wrapping column names with single quotes which makes them string literal.

    To fix the problem, just remove the single quotes around the column names:

    var sql = "insert into master_dosen(NIP,NAMA_DOSEN,KETERANGAN) ...";