语句返回Oracle错误ORA - 00984列不允许在此处

时间:2013-05-28 21:59:52

标签: c# sql oracle

我想从c#(Windows窗体)应用程序插入表格。

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();

这回来了

ORA - 00984 column not allowed here

我要填写的表格看起来像这样

picture of the table

我已经搜索了这个错误的含义,但仍然无法找到我的错误

1 个答案:

答案 0 :(得分:0)

谷歌搜索,这个错误似乎与单引号有关。

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

因此;

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);