我尝试了下面的代码,
ora.Open();
OracleCommand cmd = new OracleCommand() ;
cmd.Connection= ora;
cmd.CommandTimeout = 0;
cmd.CommandText = "update test set name= :name";
OracleParameter name = new OracleParameter("name", OracleDbType.Varchar2);
cmd.BindByName = true;
name.Value = "test";
cmd.Parameters.Add(a);
cmd.ExecuteNonQuery();
ExecuteNonQuery不起作用且没有错误。怎么了? 我使用Visual Studio 2012和Oracle Express 11g
答案 0 :(得分:2)
您正在添加名为a
的参数,而不是您创建的参数。试试这个:
ora.Open();
using (OracleCommand cmd = new OracleCommand())
{
cmd.Connection = ora;
cmd.BindByName = true;
cmd.CommandText = "update test set name = :name";
OracleParameter name = new OracleParameter("name", OracleDbType.Varchar2);
name.Value = "test";
cmd.Parameters.Add(name); // add the name parameter, not "a" object.
cmd.ExecuteNonQuery();
}
答案 1 :(得分:0)
也许你错过了准备功能?
尝试添加
在cmd.Prepare();
cmd.Parameters.Add(name);