Alek
Alek

Reputation: 329

statement gives back Oracle error ORA - 00984 column not allowed here

I want to insert into a table from a c# (Windows Forms) app.

conn.Open();
OracleCommand cmd = new OracleCommand("INSERT INTO RECIPES(id,name,time_cooking,time_prep,price,directions,user_name,submit_timestamp) VALUES (:i, :na, :time_cook, :time_pr, :pri, :dir, :us ,to_date(:sub_time ,MM/DD/YYYY))",conn);
cmd.Parameters.AddWithValue(":i",x);
cmd.Parameters.AddWithValue(":na",textBox10.Text);
cmd.Parameters.AddWithValue(":time_cook", textBox9.Text);
cmd.Parameters.AddWithValue(":time_pr",textBox8.Text);
cmd.Parameters.AddWithValue(":pri", textBox6.Text);
cmd.Parameters.AddWithValue(":dir",richTextBox2.Text);
cmd.Parameters.AddWithValue(":us",this.username);
cmd.Parameters.AddWithValue(":sub_time",DateTime.Now);

try
{
    cmd.ExecuteNonQuery();
}
catch (OracleException ex)
{
    MessageBox.Show(ex.ToString());
}

conn.Close();

this gives back

ORA - 00984 column not allowed here

the table I want to fill in looks like this

picture of the table

I have searched what this error means but still can not find my mistake

Upvotes: 0

Views: 1591

Answers (1)

Sam Leach
Sam Leach

Reputation: 12966

Googling, this error seems to be to do with single quotes.

to_date(:sub_time ,'MM/DD/YYYY')

So;

OracleCommand cmd = new OracleCommand(
"INSERT INTO RECIPES(id,name,time_cooking,time_prep,price,directions,user_name,submit_timestamp) 
VALUES (:i, :na, :time_cook, :time_pr, :pri, :dir, :us ,to_date(:sub_time ,'MM/DD/YYYY'))",conn);

Upvotes: 0

Related Questions