【问题标题】:ORA-01008: not all variables bound MVC applicationORA-01008: 并非所有变量都绑定 MVC 应用程序
【发布时间】:2019-01-31 06:40:41
【问题描述】:

我正在使用 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 语句中。 ?

谢谢。

【问题讨论】:

    标签: c# oracle


    【解决方案1】:
    myCommand.CommandText = "select user_name FROM USERS WHERE E_MAIL= :email";
    myCommand.Parameters.Add(new OracleParameter("email", USER_EMAIL ));
    

    【讨论】:

      猜你喜欢
      • 2021-12-11
      • 2019-07-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-22
      • 2021-12-18
      • 1970-01-01
      • 1970-01-01
      • 2012-09-05
      相关资源
      最近更新 更多