我正在尝试更新用户信息并收到以下错误:
你调用的对象是空的。说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
异常详细信息:System.NullReferenceException:对象引用未设置为对象的实例。
源错误:
第 20 行:'无参数构造函数第 21 行:第 22 行:
user.Email = DirectCast(e.NewValues(0), String) 第 23 行:user.Comment = DirectCast(e.NewValues(1), String) 第 24 行:user. IsApproved = CBool(e.NewValues(2))
.vb 代码是:
Protected Sub UserInfo_ItemUpdating(ByVal sender As Object, ByVal e As DetailsViewUpdateEventArgs)
'Need to handle the update manually because MembershipUser does not have a
'parameterless constructor
user.Email = DirectCast(e.NewValues(0), String)
user.Comment = DirectCast(e.NewValues(1), String)
user.IsApproved = CBool(e.NewValues(2))
Try
' Update user info:
Membership.UpdateUser(user)
' Update user roles:
UpdateUserRoles()
UserUpdateMessage.Text = "Update Successful."
e.Cancel = True
UserInfo.ChangeMode(DetailsViewMode.[ReadOnly])
Catch ex As Exception
UserUpdateMessage.Text = "Update Failed: " + ex.Message
e.Cancel = True
UserInfo.ChangeMode(DetailsViewMode.[ReadOnly])
End Try
End Sub
下面是 detailView 的 .aspx 代码:
Protected Sub UserInfo_ItemUpdating(ByVal sender As Object, ByVal e As DetailsViewUpdateEventArgs)
'Need to handle the update manually because MembershipUser does not have a
'parameterless constructor
user.Email = DirectCast(e.NewValues(0), String)
user.Comment = DirectCast(e.NewValues(1), String)
user.IsApproved = CBool(e.NewValues(2))
Try
' Update user info:
Membership.UpdateUser(user)
' Update user roles:
UpdateUserRoles()
UserUpdateMessage.Text = "Update Successful."
e.Cancel = True
UserInfo.ChangeMode(DetailsViewMode.[ReadOnly])
Catch ex As Exception
UserUpdateMessage.Text = "Update Failed: " + ex.Message
e.Cancel = True
UserInfo.ChangeMode(DetailsViewMode.[ReadOnly])
End Try
End Sub
知道我该如何排序吗?
任何帮助将不胜感激。
谢谢