ORA-00936执行insert命令时

时间:2014-08-08 12:44:31

标签: c# oracle

我查看了这部分代码,但由于某种原因,在尝试执行时仍然会出现ORA-00936错误。谁能找到我错的地方?

public void InsertActionItem(ActionItems actionItem)
{
    OracleConnection con = iscConnection();
    OracleCommand cmd = new OracleCommand("insert into cs_update_resolutions (task_id, cust_code, task_resolved, agent_entered) VALUES (@taskId, @custCode, @taskResolved, @getUser)", con);
    cmd.Parameters.Add("@taskId", OracleDbType.Int32).Value = actionItem.InsertTaskId;
    cmd.Parameters.Add("@custCode", OracleDbType.Int32).Value = actionItem.InsertCustCode;
    cmd.Parameters.Add("@taskResolved", OracleDbType.Varchar2).Value = actionItem.InsertResolution;
    cmd.Parameters.Add("@getUser", OracleDbType.Varchar2).Value = actionItem.InsertCurrentUser;
    try
    {
        con.Open();
        cmd.ExecuteNonQuery();                
        con.Close();
    }
    catch (Exception ex)
    {
        con.Close();
        MessageBox.Show(ex.ToString());
    }
}

2 个答案:

答案 0 :(得分:3)

Oracle使用:作为参数,而不是@

insert into cs_update_resolutions
(task_id, cust_code, task_resolved, agent_entered)
VALUES (:taskId, :custCode, :taskResolved, :getUser)

所以完整的代码是:

OracleConnection con = iscConnection();
OracleCommand cmd = new OracleCommand("insert into cs_update_resolutions (task_id, cust_code, task_resolved, agent_entered) VALUES (:taskId, :custCode, :taskResolved, :getUser)", con);
cmd.Parameters.Add(":taskId", OracleDbType.Int32).Value = actionItem.InsertTaskId;
cmd.Parameters.Add(":custCode", OracleDbType.Int32).Value = actionItem.InsertCustCode;
cmd.Parameters.Add(":taskResolved", OracleDbType.Varchar2).Value = actionItem.InsertResolution;
cmd.Parameters.Add(":getUser", OracleDbType.Varchar2).Value = actionItem.InsertCurrentUser;

答案 1 :(得分:0)

在您添加参数时,我不认为您需要冒号,就在您在insert语句中绑定它们时。

public void InsertActionItem(ActionItems actionItem)
{
    OracleConnection con = iscConnection();
    OracleCommand cmd = new OracleCommand("insert into cs_update_resolutions (task_id, cust_code, task_resolved, agent_entered) VALUES (:taskId, :custCode, :taskResolved, :getUser)", con);
    cmd.Parameters.Add("taskId", OracleDbType.Int32).Value = actionItem.InsertTaskId;
    cmd.Parameters.Add("custCode", OracleDbType.Int32).Value = actionItem.InsertCustCode;
    cmd.Parameters.Add("taskResolved", OracleDbType.Varchar2).Value = actionItem.InsertResolution;
    cmd.Parameters.Add("getUser", OracleDbType.Varchar2).Value = actionItem.InsertCurrentUser;
    try
    {
        con.Open();
        cmd.ExecuteNonQuery();                
        con.Close();
    }
    catch (Exception ex)
    {
        con.Close();
        MessageBox.Show(ex.ToString());
    }
}