我正在尝试使用DataRow初始化类,但是当DataRow项“LOCATION”为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
答案 0 :(得分:1)
这样的事情:
Dim location As Object = row.Item("LOCATION")
If location Is Convert.DBNull
intLocation = -1
Else
intLocation = Convert.ToInt32(location)
End If