Fixing problem in forums

Topics: Developer Discussion
Mar 27, 2007 at 1:59 AM
I don't believe this has been fixed but if it has then never mind. If you delete a user that has posted in the forums you'll get an error in forumusers.vb. What happens is the code tries to retrieve the user information with membership.getuser. The net is the returned object is empty and the following code that attempts to copy out the object properties to forumuser object fails. I ended up putting a catch there to allow the forumuser object to be set with values indicating that the user has been deleted.

There might very well be a better way to do it but here is what the new code looks like:

Using conn As SqlConnection = New SqlConnection(ConnectionString)
Try
_joined = memUser.CreationDate
_online = memUser.IsOnline
_email = memUser.Email
_loginname = memUser.UserName
_lastlogindate = memUser.LastLoginDate
Dim cmd As New SqlCommand("LoadForumUser", conn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@memberid", _memberid)
conn.Open()
Dim reader As SqlDataReader = cmd.ExecuteReader()
If reader.HasRows() And reader.Read() Then
_displayname = reader.GetString(0)
_address = reader.GetString(1)
_phone = reader.GetString(2)
_posts = reader.GetInt32(3)
_lastpostdate = reader.GetDateTime(4)
_signature = reader.GetString(5)
_bio = reader.GetString(6)
_sortdesc = reader.GetBoolean(7)
_msgsperpage = reader.GetInt32(8)
_showavatars = reader.GetBoolean(9)
_showsignatures = reader.GetBoolean(10)
_sendwatchemails = reader.GetBoolean(11)
_showemail = reader.GetBoolean(12)
End If
Catch
_joined = "1/1/2000"
_online = False
_email = "N/A"
_loginname = "Deleted"
_lastlogindate = "1/1/2000"
_displayname = "Deleted User"
_address = "Nowheresville"
_phone = ""
_posts = 0
_lastpostdate = "1/1/2000"
_signature = "Gone Daddy Done!"
_bio = "Lost in time..."
_sortdesc = False
_msgsperpage = 0
_showavatars = False
_showsignatures = False
_sendwatchemails = False
_showemail = False
End Try
conn.Close()


Hope that helps someone out.

Michele
Coordinator
Mar 27, 2007 at 4:30 AM
So this goes on ForumUser.vb? We will be redoing the forums for v3, but thanks for the fix for v2! I will check it out and make sure it works.
Mar 29, 2007 at 4:45 PM
Thanks for this great tip, really did save me a lot :)
Mar 29, 2007 at 7:15 PM
Are you still single? ;-))
Mar 29, 2007 at 10:05 PM
Haven't been asked that in a while..... :-)