Last post Jan 28, 2009 11:44 AM by MetalAsp.Net
Jan 28, 2009 11:35 AM|cmt9000|LINK
I am using a DataReader to get data from a database. For some reason, I keep getting this error "Arithmetic operation resulted in an overflow."
The error occurs on the line: courseID = (dr.Item("courseId"))
courseID is set as int in the SQL Server database. I did a response.Write(dr.Item("courseId")) and it returns
479, which is an integer. So I am not sure why it is erroring out.
Dim courseID As Integer
If dr.HasRows Then
Do While dr.Read()
If Not IsDBNull(dr.Item("courseId")) Then
courseID = (dr.Item("courseId"))
Does anyone see anything I missed?Thanks!
Jan 28, 2009 11:44 AM|MetalAsp.Net|LINK
dr.Item("courseId") return an object. I think you need to cast it to an int.
courseID = Convert.ToInt32(dr.Item("courseId"))
Edit: Otherwise, it may be that for one of the items, it's returning posibly a null value. The Convert.ToInt32 will return a zero in that case and should solve your problem.