tags:

views:

19

answers:

1

Hello, 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!

A: 

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
Its not always a string...is that a problem?
grady
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