Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Conversion from type 'DBNull' to type 'Integer' is not valid.
Posted
Comments
Jameel VM 12-Dec-14 4:12am    
where is the code?
SathishRam 12-Dec-14 4:38am    
Dim ClassRosterID As Integer
Dim dr As System.Data.DataRow
For Each dr In _dtAttendees.Rows
oDM.Initialize("ClassRoster_Insert")
oDM.AddOutputParameter("ClassRosterID", 41)
If _ClassChainID < 1 Then oDM.AddParameter("ClassID", _ClassID) 'Only ClassID or ClassChainID is present
If _ClassChainID > 0 Then oDM.AddParameter("ClassChainID", _ClassChainID)
If _SoldToCustomerID > 0 Then oDM.AddParameter("CustomerID", _SoldToCustomerID) ' Only CustomerID or ProspectID is present and isSKMEmployee = 0
If _SoldToProspectID > 0 Then oDM.AddParameter("ProspectID", _SoldToProspectID)
'@isSKMEmployee Int = 0 -- If Employee then CustomerID & ProspectID are both blank

Select Case Right(dr("PKID").ToString, 1)
Case "U" ' User
oDM.AddParameter("StudentUserID", Mid(dr("PKID").ToString, 2))
Case "A" ' Alternate contact
oDM.AddParameter("StudentCustomerAlternateContactID", Mid(dr("PKID").ToString, 2))
Case "N" ' New user
Case "M" ' Primary user on account
Case "R" ' Roster
End Select

oDM.AddParameter("FirstName", dr("FirstName"))
oDM.AddParameter("LastName", dr("LastName"))
oDM.AddParameter("Phone", dr("Phone"))
oDM.AddParameter("Email", dr("Email"))
oDM.AddParameter("RegisterUserID", _oUser.ThisUserID)

oDM.AddParameter("Status", Status)
oDM.AddParameter("isPaid", isPaid)
If TransactionID > 0 Then oDM.AddParameter("TransactionID", TransactionID)
'@Note nvarchar(max) = Null
oDM.AddParameter("UpdatedBy", _oUser.drUser("FullName"))
_DBUpdateLog.Append(oDM.OutputCallConfiguration())
ClassRosterID = oDM.ExecuteStoreProcedure("ClassRosterID")
Next
Thanks7872 12-Dec-14 4:24am    
And which part of this error is unclear? Have you searched using Google? Why you people expect someone will do something for you?
SathishRam 12-Dec-14 4:36am    
can u able to answer cause for a reason ,an error is common to all and has common solution for that ,it's just a help,not i'm asking you to work for me
Thanks7872 12-Dec-14 4:40am    
https://www.google.co.in/search?q=Conversion+from+type+%27DBNull%27+to+type+%27Integer%27+is+not+valid&oq=Conversion+from+type+%27DBNull%27+to+type+%27Integer%27+is+not+valid&aqs=chrome..69i57&sourceid=chrome&es_sm=93&ie=UTF-8

May i know why this 9,840 results doesn't work for you?

You need to check for DBNull values using IsDBNull. Check this link:
http://msdn.microsoft.com/en-us/library/tckcces5%28v=vs.90%29.aspx[^]

Good luck!
 
Share this answer
 
1.You are trying to read an int value from the DB that allow also NULL values, and your current field has NULL value in the database that is equivalent with DBNull in the C# code.

2.The solution is, that in your reader to manage this case like in the next example:
C#
int stockQuantity = (reader["Stock"] == DBNull.Value ? 0 : (int)reader["Stock"]);
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900