日期:2014-05-18  浏览次数:21286 次

用C#连接Oracle出错啦,帮我看看
ORA-00936: 缺失表达式
C# code
public static int AddUsers(Users user)
        {
            int n = 0;
            try
            {
                string sql = "insert into users values(id_seq.nextval,'@name',@age,'@sex');";
                OracleParameter name = new OracleParameter("@name",user.Name);
                OracleParameter age = new OracleParameter("@age", user.Age);
                OracleParameter sex = new OracleParameter("@sex",user.Sex);

                OracleCommand command = command = new OracleCommand(sql, DBHelper.connection);
                command.Parameters.Add(name);
                command.Parameters.Add(age);
                command.Parameters.Add(sex);

                DBHelper.connection.Open();
                Console.WriteLine(sql);
                n = command.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            finally
            {
                DBHelper.connection.Close();
            }
            return n;
        }
    


其中,name、age、sex的值都取到了,在执行添加的时候报错了

------解决方案--------------------
C# code

string sql = "insert into users (ID,NAME,AGE,SEX) values (id_seq.nextval,:NAME,:AGE,:SEX)";