日期:2014-05-17  浏览次数:20545 次

简单ORacle插入数据问题,求教!!
异常:ORA-01036: 非法的变量名/编号

代码

C# code
private string DoInsert(HttpContext context)
        {
            string result = "";
            string name=context.Request.Params["name"];
            string parentid = context.Request.Params["parentid"];
            if (name != null && parentid != null)
            {
                OracleConnection conn = new OracleConnection("Data Source=wgyx;user=wgyx;password=wgyx;");
                OracleCommand cmd = new OracleCommand("INSERT INTO newclass ( cName, parentid ) VALUES(name,parentid)", conn);
                cmd.Parameters.AddWithValue("name", name);
                cmd.Parameters.AddWithValue("parentid", int.Parse(parentid));
                try
                {
                    conn.Open();
                    cmd.ExecuteNonQuery();
                    conn.Close();
                    cmd.CommandText = "Select max(id) from newclass";
                    cmd.Parameters.Clear();
                    conn.Open();
                    result = cmd.ExecuteScalar().ToString();
                    conn.Close();
                }
                catch (Exception ex)
                {
                    result = "-1";
                }
                finally
                {
                    conn.Close();
                }
            }
            else
            {
                result = "-1";
            }
            return result;
        }


不知道上面的代码哪里出错了?

------解决方案--------------------
int.Parse(parentid) 改
Convert.ToInt32(parentid)
------解决方案--------------------
values里面改为values(@name,@parentid)试试