I am trying to get a Custom personalization provider to work with my
existing SQL table. When I try and call <%= Profile.CompanyName
%> in the page I get
Object reference not set to an instance of an object.
Line 40: Public Overridable Property CompanyName() As String
Line 41: Get
Line 42: Return CType(Me.GetPropertyValue("CompanyName"),String)
Line 43: End Get
Line 44: Set
What do I need to do to retrieve Profile values from my table?
Here's the GetPropertyValues from the class
Public Overrides Function GetPropertyValues(ByVal context As
System.Configuration.SettingsContext, ByVal ppc As
System.Configuration.SettingsPropertyCollection) As
System.Configuration.SettingsPropertyValueCollection
Dim connString As String
connString = "Server=xxx;User ID=xxx;password=xxx;Database=xxx"
Dim commString As String
commString = "SELECT CompanyID, CompanyName, Email from Company WHERE
Userid = 123123123"
Dim conn As SqlConnection = New SqlConnection(connString)
Dim cmd As SqlCommand = New SqlCommand(commString, conn)
' Open the connection and execute the reader
conn.Open()
Dim reader As SqlDataReader
reader = cmd.ExecuteReader()
While reader.Read()
ppc("CompanyID").DefaultValue = reader("CompanyID")
ppc("CompanyName").DefaultValue = reader("CompanyName")
ppc("Email").DefaultValue = reader("Email")
End While
' Close connections
reader.Close()
conn.Close()
cmd = Nothing
End Function