Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 272
Nicolas Avatar asked May 18 '26 04:05

Nicolas


1 Answers

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) ...";
like image 194
John Woo Avatar answered May 20 '26 18:05

John Woo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!