我有以下方法,两个参数都是空的
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:并非所有变量都绑定了"
如果我只使用一个参数那么它很好但是当我添加第二个时它失败了" ORA-01008:并非所有变量都绑定了"
提前致谢
答案 0 :(得分:0)
command.CommandText = "select count(id) from Table1 "
+ "where decode(Column1, :PARAM1, 1) = 1 AND decode(Column2, :PARAM2, 1) = 1";