1

我正在尝试执行插入但收到此错误:[异常:处理命令期间发生一个或多个错误。ORA-00936: 缺少表达式]

它适用于选择查询。

table structure is as follow
database-oracle 10g
table name-investor_info

investor_id-number
first_name-varchar
lastname-varchar
age-number
location-varchar
contact_number-varchar
email-varchar
checked-number-number


public void insert_details(string fname,string lname, int age, string location, string contactnumber, string email)
    {
        int id = get_id()+1;
        int check=0;



        string query = "INSERT INTO INVESTOR_INFO (INVESTOR_ID,FIRST_NAME,LAST_NAME,AGE,LOCATION,CONTACT_NUMBER,EMAIL,CHECKED) VALUES (@val1,@val2,@val3,@val4,@val5,@val6,@val7,@val8);";

        try
        {
            conn.Open();
            OleDbCommand command1 = new OleDbCommand(query,conn);
            command1.Parameters.AddWithValue("@val1", id);
            command1.Parameters.AddWithValue("@val2", fname);
            command1.Parameters.AddWithValue("@val3", lname);
            command1.Parameters.AddWithValue("@val4", age);
            command1.Parameters.AddWithValue("@val5", location);
            command1.Parameters.AddWithValue("@val6", contactnumber);
            command1.Parameters.AddWithValue("@val7", email);
            command1.Parameters.AddWithValue("@val8", check);

            command1.CommandType = CommandType.Text;

            command1.ExecuteNonQuery();

           // conn.Close();
        }
        catch (Exception e)
        {
            throw new Exception(e.Message);
        }
        finally
        {
            conn.Close();
        }

    }//end of insert
4

3 回答 3

1

删除字符串 QUERY 中的分号

它应该是

string query = "INSERT INTO INVESTOR_INFO (INVESTOR_ID,FIRST_NAME,LAST_NAME,AGE,LOCATION,CONTACT_NUMBER,EMAIL,CHECKED) VALUES (@val1,@val2,@val3,@val4,@val5,@val6,@val7,@val8)";
于 2012-12-27T09:30:22.437 回答
0

从字符串查询中删除分号并尝试如下所示,

字符串查询 = "INSERT INTO INVESTOR_INFO (INVESTOR_ID,FIRST_NAME,LAST_NAME,AGE,LOCATION,CONTACT_NUMBER,EMAIL,CHECKED) 值 (@val1,@val2,@val3,@val4,@val5,@val6,@val7,@val8) ";

始终使用表名指定架构名称。(schemeName.tableName)

于 2012-12-27T09:30:28.113 回答
0

我已经有一段时间没有在 Oracle 上工作了,但是您是否尝试过将参数替换为@a :。参考以下文章:

http://msdn.microsoft.com/en-us/library/system.data.oracleclient.oraclecommand.parameters.aspx

于 2012-12-27T09:36:38.073 回答