2013-03-08 53 views
1

我有以下的方法和两个PARAMATERS都为空的OracleCommand查询空参数中凡 - ORA-01008:结合并非所有变量

布尔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:未绑定的所有变量”

如果我只用一个参数,那么它的罚款,但是当我将其添加失败,“ORA-01008第二:未绑定”

在此先感谢

回答

0
command.CommandText = "select count(id) from Table1 " 
+ "where decode(Column1, :PARAM1, 1) = 1 AND decode(Column2, :PARAM2, 1) = 1"; 
+0

感谢它的工作对我的INT列,但没有日期和字符串列 – MicroMan 2013-03-08 13:17:08

+0

@Jeepers所有变量 - 举个例子:你如何传递参数值以及返回的错误。 – 2013-03-08 13:27:39

+0

这是用户错误,它适用于所有......谢谢 – MicroMan 2013-03-08 14:53:16