Dim trv1 As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim trv2 As WinForm.TreeView = e.Form.Controls("TreeView2")
Dim pn1 As WinForm.TreeNode = trv1.SelectedNode
Dim pn2 As WinForm.TreeNode = trv2.SelectedNode
Dim p1 As DataRow = pn1.DataRow
Dim p2 As DataRow = pn2.DataRow
If pn1 Is Nothing Then
MessageBox.show("请选择所属部门!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning) ' 不选择Pn1时,我想让提示窗口提示MessageBox;但实际提示:未将对象引用设置到对象的实例。
Else
If pn2 Is Nothing Then
MessageBox.show("请选择所属岗位!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning) '不选择Pn2时,我想让提示窗口提示MessageBox;但实际提示:未将对象引用设置到对象的实例。
Else
Dim r As Row = Tables("UserInfo").AddNew()
r("DepartmentName") = p1("DepartmentName")
r("DepartmentId") = p1("DepartmentId")
r("PositionName") = p2("PositionName")
r("PositionId") = p2("PositionId")
End If
End If
Dim p1 As DataRow = pn1.DataRow这里就出错了,如果pn1是空值,使用空对象的属性肯定会出错。所以应该在使用这个对象任何属性之前判断