0

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

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Alek
  • 299
  • 2
  • 4
  • 12
  • This error most commonly occurs when you try to include a column name in the VALUES clause of an INSERT statement. Check that first. – rivarolle May 28 '13 at 22:16
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders May 29 '13 at 00:39

1 Answers1

0

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);
Sam Leach
  • 12,746
  • 9
  • 45
  • 73
  • Yep, here. https://forums.oracle.com/forums/thread.jspa?threadID=265416 http://stackoverflow.com/questions/10501521/column-not-allowed-here-error-in-insert-statement http://stackoverflow.com/questions/3924558/oracle-error-column-not-allowed-here – Sam Leach May 28 '13 at 22:18
  • That seems to have work. But now a new error occured. ora-01843 not a valid month I use the oracle format from my base. I dont know why this came up – Alek May 28 '13 at 22:19
  • Never mind I just need it to convert the date toString("MM/dd/yyyy") Thank you for your help – Alek May 28 '13 at 22:22
  • 1
    @Alek You might want to instead set the parameter type to date. It's cleaner than converting to a string and then converting it back to a date – Conrad Frix May 28 '13 at 22:25
  • @Sam that's interesting I meant a search link. [My search](google.com/search?setmkt=en-US&q=00984+column+not+allowed+here) didn't find those so I was curious about what terms you searched and how you spotted the `to_date`. As an aside how you found the answer is completely irrelevant. Even if it was [from a comment](http://meta.stackexchange.com/a/143517) – Conrad Frix May 28 '13 at 22:48
  • search?q=oracle+column+not+allowed+here+during+insert. Top 3 results. I scanned the query and found the missing quotes. I have been googling things since before google and when someone says they have searched but not found the answer, I usually try to prove them wrong. You commented the same answer, great. – Sam Leach May 28 '13 at 23:09