0

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!

grady
  • 12,281
  • 28
  • 71
  • 110

1 Answers1

0

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!

Kieren Johnstone
  • 41,277
  • 16
  • 94
  • 144
  • Its not always a string...is that a problem? – grady Jul 21 '10 at 09:23
  • 1
    Each parameter must be of a consistent, set type: so you should use the `DbType` most appropriate. It doesn't need to be `String`, but it needs to be something, and that should match the type of parameter you are setting the value of. – Kieren Johnstone Jul 21 '10 at 10:54