Search code examples
c#dbcommand

AddInParameter and NULL?


I have problems inserting a null paramater with the AddInParameter method.

cmd.AddInParameter(someString, someValueWhichCanBeNULL)

As soon as the 2nd param is null, it fails. I also Tried DBNull.Value, fails too. Ideas?

The message is: AddInParameter @MyParam with null value or Unsupported Property Type: DBNull

Thanks!


Solution

  • Use the overload of AddInParameter that takes three arguments; you want this:

    cmd.AddInParameter(someString, DbType.String, someValueWhichCanBeNULL);
    

    (It can't determine the type of the parameter from the DBNull.Value alone)

    Hope that helps!