Yes, that was it. I wrapped a While Reader.Read() around the For Each loop and my 'GetPropertyValues' method now works. My testing now shows that references to Profile.ZipCode in my .aspx pages will 'get' data from my custom profile table instead of the default aspnet profile table. Thank you. That's a nice victory.
No resting though. I now need to figure out the simplest possible code to 'set' data in my custom profile table via the 'SetPropertyValue' method of my custom profile provider class. I've been working on it myself today to see how far I can take it and I think I've hit a bit of a wall. I can use a few more of your excellent tips if possible.
I started figuring out how to code the SetPropertyValue method by reusing what I know works so far - the code for the GetPropertyValues and tweaking it. That has only taken my so far.
I know my requirements are to register new users and profiles for the first time and also update existing users profile data - so, the sqlcommand I'll need is INSERT and UPDATE, right? I don't think I need the SELECT command this time.
Also, my new users registration process as a requirement to first ask potential new registrants to enter a 'ValidUserCode' into a textbox (and validate it against numbers stored in a separate table of valid codes). When a registrant enters a valid code that code, at the end of the rest of the registration process, becomes part of that users stored profile data. I've already worked out all that, including adding the ValidUserCode as an custom profile property with the anonomous attribute equal to true - and added code to global.asax which acts to remove the anonomous entries in the user and profile tables when that new user is authenticated. That all appears to work using the default profile provider, however, now I need to figure out how to get it to work when I write the data to my custom tables. I've read all the papers describing this and seen all the sample code available so far, but none of the examples simply provide samples in vb.net and in the common usage scenario I've described, including the database reference.
Also, I'm challenged with how to properly declare the parameters and I don't even know if I need the For Each loop or if the DataReader is appropiate for this method.
So, below is the code I have so far that doesn't work, but I've got to start somewhere. Any tips on how to amend the code below to work?
Thanks.
_____
Public Overrides Sub SetPropertyValues(ByVal context As System.Configuration.SettingsContext, ByVal ppc As System.Configuration.SettingsPropertyValueCollection)
Dim svc As SettingsPropertyValueCollection = New SettingsPropertyValueCollection()
Dim connection As SqlConnection
Dim command As SqlCommand
Dim username As String = HttpContext.Current.User.Identity.Name
connection = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True")
command = New SqlCommand("UPDATE [User_Profiles] SET [ValidUserCode] = @ValidUserCode, [ZipCode] = @ZipCode " _
& "WHERE [UserName] = '" _
& username & "'", connection)
command.Parameters.AddWithValue("@ValidUserCode", SqlDbType.VarChar)
command.Parameters.AddWithValue("@ZipCode", SqlDbType.VarChar)
Dim reader As SqlDataReader
connection.Open()
reader = command.ExecuteReader
While reader.Read()
For Each prop As SettingsProperty In ppc
Dim pv As SettingsPropertyValue = New SettingsPropertyValue(prop)
Select Case prop.Name
Case "ValidUserCode"
pv.PropertyValue = reader(
"ValidUserCode")
Case "ZipCode"
pv.PropertyValue = reader(
"ZipCode")
End Select
svc.Add(pv)
Next
End While
connection.Close()
End Sub