Try passing DbNull.Value:
public virtual DbParameter CreateParameter(string parameterName, object value)
{
DbParameter parm = dbProvider.CreateParameter();
parm.ParameterName = parameterName;
if (value == null)
value = DBNull.Value;
parm.Value = value;
return parm;
}
+++ Rick ---
>Hi everybody,
>
>I am trying to conditionally assign null value to a parameter and it doesn't seem to work.
>
>Here is my current code
>
>
>insertCommand.Parameters.Add("@accessPassNo", SqlDbType.Decimal, 17).Value = (this.passTable == PassTable.Access) ? passNo : (Int64?)null;
>
>And it returns the following error
>
>The parameterized query '(@datetime datetime,@quantity int,@BenefitId int,@gstPassNo deci' expects the parameter '@accessPassNo', which was not supplied.
>
>So, my question is - how should I properly assign null value? I tried using DbNull.Value, but then I can not even compile that code because of the problem with types.
>
>Thanks in advance.
>
>UPDATE. I have an idea to try - instead of inline iif I'll try IF ELSE and assign DbNull.Value this way.