Membership.Updateuser not really updating the database.
Posted
by Shimrod
on Stack Overflow
See other posts from Stack Overflow
or by Shimrod
Published on 2010-04-27T13:40:01Z
Indexed on
2010/04/27
13:43 UTC
Read the original article
Hit count: 285
Hi everybody,
I'm currently working on a membership system for my web application, which is based on forms authentication from the framework.
I created some users with the integrated tool, and the login is perfectly working. But now what I want to do is to give administrator the capability to create, modify, delete users.
So here is what I've got right now:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim muc As MembershipUserCollection = Membership.GetAllUsers()
ComboBox1.DataSource = muc
ComboBox1.DataValueField = "UserName"
ComboBox1.DataTextField = "UserName"
ComboBox1.DataBind()
End Sub
Protected Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim userName As String = ComboBox1.SelectedValue
Dim mu As MembershipUser = Membership.GetUser(userName)
Dim userRoles As String() = Roles.GetRolesForUser(userName)
tbComments.Text = mu.Comment
tbEmail.Text = mu.Email
lblUserName.Text = mu.UserName
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim userName As String = ComboBox1.SelectedValue
Dim mu As MembershipUser = Membership.GetUser(userName)
If Not mu Is Nothing Then
Try
mu.Comment = tbComments.Text
Membership.UpdateUser(mu)
mu.Email = tbEmail.Text
Membership.UpdateUser(mu)
mu.IsApproved = True
Membership.UpdateUser(mu)
mu = Nothing
Catch ex As Exception
Console.WriteLine(ex.ToString())
End Try
End If
DetailPanel.Visible = False
End Sub
The problem is that the record doesn't seem to be updated in the database.
I made the multiple calls to Membership.UpdateUser
after reading this blog entry, but it didn't change anything.
A strange think I noticed while debugging, is that when I enter the Button1_Click
method, Membership.GetUser(userName)
returns me values from my precedent attempt ! I don't really understand what I'm missing.
Does someone have a clue ?
Thanks in advance !
© Stack Overflow or respective owner