1

我有以下方法,两个参数都为空

bool hasValue = HasValue(null,null);

    internal bool HasValue(int? param1, int? param2)
    {
        int count = 0;
        using (var conn = new OracleConnection(connectionString))
        {
                using (var command = conn.CreateCommand())
                {
                    command.CommandText = "select count(id) from  Table1 "
                    + "where ((Column1 = :PARAM1 and :PARAM1 Is Not Null) Or (Column1 Is Null and :PARAM1 Is Null)) "
                    + "AND ((Column2 = :PARAM2 and :PARAM2 Is Not Null) Or (Column2 Is Null and :PARAM2 Is Null))";
                    command.Parameters.Add("PARAM1", OracleDbType.Int16, 0, param1, ParameterDirection.Input);
                    command.Parameters.Add("PARAM2", OracleDbType.Int16, 0,param2, ParameterDirection.Input);
                    command.Connection.Open();
                    count = Convert.ToInt16(command.ExecuteScalar());

                    command.Connection.Close();
                }
        }

        return count > 0;
    }

该方法失败并出现以下错误“ORA-01008: not all variables bound”

如果我只使用一个参数,那么它很好,但是当我添加第二个参数时它会失败并显示“ORA-01008:并非所有变量都绑定”

提前致谢

4

1 回答 1

0
 command.CommandText = "select count(id) from  Table1 "
 + "where decode(Column1, :PARAM1, 1) = 1 AND decode(Column2, :PARAM2, 1) = 1";
于 2013-03-08T11:24:46.863 回答