aspx insert to Oracle得到ORA-01008错误

时间:2015-11-19 01:44:07

标签: c# asp.net oracle oracle11g oledb

我在Oracle 11g中创建了表,

CREATE TABLE "TABLE1" 
(
    "COLUMN1" VARCHAR2(20 BYTE), 
    "COLUMN2" VARCHAR2(20 BYTE)
) 

System.Data.OleDb联系,connectionStrings为:

<connectionStrings>
    <add name="DBConnStr" connectionString="Provider=msdaora;Data Source=test;User Id=test;Password=test;" />
</connectionStrings>

并尝试将数据插入表TABLE1

private void testInsert()
{
    string sql = "";
    int recordsAffected = 0;

    using (OleDbConnection openCon = new OleDbConnection(constr))
    {
        sql = @"insert into table1 (column1, column2) values (:aaa, :bbb)";
        using (OleDbCommand command = new OleDbCommand(sql))
        {
            command.Connection = openCon;

            command.Parameters.AddWithValue(":aaa", "test");
            command.Parameters.AddWithValue(":bbb", "0123456");

            openCon.Open();
            recordsAffected = command.ExecuteNonQuery(); // <-- error here
            openCon.Close();
        }
    }
}

ORA-01008行出现command.ExecuteNonQuery ()错误。为什么Oracle声称不是所有变量都绑定了?

如果我用:替换冒号(@)前缀,则会出现ORA-00936错误。如果我删除所有前缀,我得到ORA-00984错误。将数据插入Oracle表的正确方法是什么?

提前致谢。

1 个答案:

答案 0 :(得分:0)