Passing Null/empty string to Oracle stored procedure from asp.net

前端 未结 1 769
心在旅途
心在旅途 2021-01-25 05:33

We have an ASP.NET web service that invokes a stored procedure on our DB (Oracle 11g). The problem is that the call to the procedure blows up every time an empty string is pass

1条回答
  •  -上瘾入骨i
    2021-01-25 06:24

    You can do the following for any nullable parameters.

    oleDBCmd.Parameters.Add(new OracleParameter("to_dt", OracleType.NVarChar));
    if(string.IsNullOrEmpty(toDateStr)) {
        oleDBCmd.Parameters["to_dt"].Value = DBNull.Value;
    } else {
        oleDBCmd.Parameters["to_dt"].Value = toDateStr;
    }
    oleDBCmd.Parameters["to_dt"].Direction = ParameterDirection.Input;
    

    That way, you're not relying on string -> null conversion by the oracle adapter.

    Edit: If this doesn't fix the issue, it is most possibly a mismatch between types, check NVarChar vs VarChar

    0 讨论(0)
提交回复
热议问题