2

I wish to pass Null Value to the parameter as follow:

_db.AddInParameter(dbCommand, "Id", DBNull.Value, myContactPerson.Id);

I am receiving the following error :

"can not convert "System.DBNull to System.Data.DbType".

I know the meaning of this error.

But i need to supply null value to myContactPerson.Id

How can i achieve this ?

user146584
  • 701
  • 2
  • 11
  • 18

2 Answers2

1

If myContactPerson.Id isn't an auto-number, then why not just pass 0.

Kredns
  • 36,461
  • 52
  • 152
  • 203
  • yes .I achieved the result by passing Zero.sometimes unbale to think the other way round. :) – user146584 Aug 10 '09 at 00:49
  • 1
    @rengaseshan: Your concentrating to hard. I do that all the time. I find it's best to just take a break, and when your not thinking about the problem, it'll just come to you. ;-) – Kredns Aug 10 '09 at 00:52
0

DBType should be passed in that parameter and should match your the dbtype (string, int, etc.) for the table that you are comparing with in your database. You would replace your value field "myContactPerson.Id" with DBNull.Value to always pass the null value.

Jay
  • 2,644
  • 1
  • 30
  • 55
  • _db.AddInParameter(dbCommand, "Id", System.Data.DBType.Int32, 0); Don't think you can pass null to an Int db type....Better option would be to have it autogenerate. – Jay Aug 10 '09 at 00:51