ORA-01008:并非所有变量都绑定了MVC应用程序

时间:2018-08-24 18:56:30

标签: c# oracle

我正在将VS2013与Oracle 11g一起使用。我正在尝试根据电子邮件从Oracle检索数据。

有效,因为该电子邮件在WHERE子句中进行了硬编码。

var connection = new OracleConnection(connectionString); 
 connection.Open();
 OracleCommand myCommand = connection.CreateCommand();
 myCommand.BindByName = true;
 myCommand.CommandText = "select user_name FROM USERS WHERE E_MAIL= 'john@hotmail.com'";

当我尝试传递失败的变量时。

  

ORA-01008:并非所有变量都已绑定

var USER_EMAIL = "john@hotmail.com"; // NEW DECLARATION. 
 var connection = new OracleConnection(connectionString); 
 connection.Open();
 OracleCommand myCommand = connection.CreateCommand();
 myCommand.BindByName = true;
 myCommand.CommandText = "select user_name FROM USERS WHERE E_MAIL= :USER_EMAIL";

如何在oracle中将变量传递到select语句中。 ?

谢谢。

1 个答案:

答案 0 :(得分:1)

myCommand.CommandText = "select user_name FROM USERS WHERE E_MAIL= :email";
myCommand.Parameters.Add(new OracleParameter("email", USER_EMAIL ));