An int can be 0. However, you cannot assign null to an int unless it is declared as nullable (by adding the ? after the keyword as part of its declaration). The problem was that your db.QueryValue returned null, and you tried to assign that to a non-nullable
int.
wavemaster
Participant
1279 Points
1127 Posts
Cannot convert null to 'int' because it is a non-nullable value type
Oct 13, 2012 03:19 PM|LINK
The above error had me stumped for a while. But I figured it out
My table UserProfileRev has two columns:
UserId Int Primary Key Identity
Phone nvarchar Primary Key
UserId Phone
2 +18005551212
4 +18885551212
running the query below I get the
int userfrom = db.QueryValue("SELECT UserId FROM UserProfileREV WHERE Phone = @0", From);Apparently, int cannot be zero, if it is you get the above error.
The solutions are:
Mikesdotnett...
All-Star
154905 Points
19866 Posts
Moderator
MVP
Re: Cannot convert null to 'int' because it is a non-nullable value type
Oct 13, 2012 04:49 PM|LINK
An int can be 0. However, you cannot assign null to an int unless it is declared as nullable (by adding the ? after the keyword as part of its declaration). The problem was that your db.QueryValue returned null, and you tried to assign that to a non-nullable int.
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter