i am trying to perform insert but getting this error: [Exception: One or more errors occurred during processing of command. ORA-00936: missing expression]
我试图执行插入但得到此错误:[例外:在处理命令期间发生了一个或多个错误。 ORA-00936:缺少表达]
it works for select query.
它适用于选择查询。
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
3 个解决方案
#1
1
Remove the semicolon in string QUERY
删除字符串QUERY中的分号
it should be
它应该是
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)";
#2
0
Remove semicolon from the string query and try like below,
从字符串查询中删除分号,并尝试如下,
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)";
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) “;
Always specific the schema name with table name.(schemeName.tableName)
始终使用表名特定模式名称。(schemeName.tableName)
#3
0
I have not worked on Oracle for a while, but have you tried replacing the @
with a :
for the parameters. Refer to the following artice:
我有一段时间没有在Oracle上工作过,但你是否尝试用参数替换@:请参阅以下技巧:
http://msdn.microsoft.com/en-us/library/system.data.oracleclient.oraclecommand.parameters.aspx
http://msdn.microsoft.com/en-us/library/system.data.oracleclient.oraclecommand.parameters.aspx
#1
1
Remove the semicolon in string QUERY
删除字符串QUERY中的分号
it should be
它应该是
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)";
#2
0
Remove semicolon from the string query and try like below,
从字符串查询中删除分号,并尝试如下,
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)";
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) “;
Always specific the schema name with table name.(schemeName.tableName)
始终使用表名特定模式名称。(schemeName.tableName)
#3
0
I have not worked on Oracle for a while, but have you tried replacing the @
with a :
for the parameters. Refer to the following artice:
我有一段时间没有在Oracle上工作过,但你是否尝试用参数替换@:请参阅以下技巧:
http://msdn.microsoft.com/en-us/library/system.data.oracleclient.oraclecommand.parameters.aspx
http://msdn.microsoft.com/en-us/library/system.data.oracleclient.oraclecommand.parameters.aspx