-1

I'm trying to initialize a class using a DataRow, But when the DataRow item "LOCATION" is a Null value I receive an error. How can I load these variables with their appropriate datatype values when the row item is null?

    Public Sub New(ByVal row As DataRow)
                intID = row.Item("ID")
                strDepartmentCode = row.Item("DEPARTMENT_CODE")
                strDepartmentName = row.Item("DEPARTMENT_NAME")
                intLocation = row.Item("LOCATION")
    End Sub
  • 1
    I don't mean to sound harsh, but it seems like you haven't even tried to search S/O for this answer. Take a moment to look to the right, under the heading "Related". There are several similar questions like yours that have valid answers. Also, try searching the site. I'm certain this question has been asked dozens of times before. Start by searching with the exact error message that you are getting. – tgolisch Jun 19 '14 at 15:50
  • 1
    I'm new to S/O and I appreciate the advice. I'll take those tips into account next time. – lilbrettbro Jun 19 '14 at 16:03

1 Answers1

1

Something like this:

Dim location As Object = row.Item("LOCATION")
If location Is Convert.DBNull
  intLocation = -1
Else
  intLocation = Convert.ToInt32(location)
End If
Victor Zakharov
  • 25,801
  • 18
  • 85
  • 151