1

I'm trying to pass a parameter into a stored proc using ADO.NET. This paramater is of type int but the field in the database is nullable. Here's my code:

AddInParameter(cmd, "@i_Required_License_List_PKID", DbType.Int32, RequiredLicenseListPkid==""? null : Convert.ToInt32(RequiredLicenseListPkid);

When I do this I get an error saying that there's no conversion between null and int.

I have also tried DbNull.Value in place of null but with the same result.

I can't seem to find any nullable parameter types in the DbType class but I wonder is that the solution.

Sperick
  • 2,691
  • 6
  • 30
  • 55

2 Answers2

2

Use: DBNull.Value;

as the value of the parameter

Shaul Zuarets
  • 839
  • 2
  • 10
  • 20
0

AddInParameter(cmd, "@i_Required_License_List_PKID", DbType.Int32, RequiredLicenseListPkid==""? DBNull.Value: Convert.ToInt32(RequiredLicenseListPkid);

Wiki
  • 92
  • 1
  • 8