eramgarden Posted December 5, 2005 Posted December 5, 2005 (edited) Not sure why I get "Object reference not set to an instance of an object" -- This is what I have: Created a User Object: Public Class UserFields Private intUserLoginNum As Integer = 0 Private strUserEmail As String = "" Public Property UserLoginNum() As String Get Return intUserLoginNum End Get Set(ByVal Value As String) intUserLoginNum = Value End Set End Property Public Property [b]email_address()[/b] As String Get Return strUserEmail End Get Set(ByVal Value As String) strUserEmail = Value End Set End Property End Class Trying to assign a value to a property in my Function Dim objUserFields As UserFields Dim dr As SqlClient.SqlDataReader Dim cnn As New SqlClient.SqlConnection(...) Dim cmd As New SqlClient.SqlCommand("usp_rt_get_userEmail", cnn) cnn.Open() cmd.Parameters.Add("@UserLogin", userLoginId) cmd.CommandType = CommandType.StoredProcedure Dim dt As New DataTable Dim da As New SqlDataAdapter(cmd) da.Fill(dt) [b]objUserFields.email_address = dt.Rows(0)("email_address") 'I get the error here [/b] Columns in Datatable are "email_address" and "User_login_id"... What am I missing?? Edited December 6, 2005 by eramgarden Quote
hsueh001 Posted December 6, 2005 Posted December 6, 2005 You never instantiated objUserFields Before your error add the line Dim objUserFields as New UserFields This should solve your problem. Sorry that I have to start a new thread but the other one is down below getting burried: http://www.aspmessageboard.com/forum/ASPPlus.asp?M=816159&T=816150&F=36&P=1 Not sure why I get "Object reference not set to an instance of an object" -- This is what I have: Created a User Object: Public Class UserFields Private intUserLoginNum As Integer = 0 Private strUserEmail As String = "" Public Property UserLoginNum() As String Get Return intUserLoginNum End Get Set(ByVal Value As String) intUserLoginNum = Value End Set End Property Public Property [b]email_address()[/b] As String Get Return strUserEmail End Get Set(ByVal Value As String) strUserEmail = Value End Set End Property End Class Trying to assign a value to a property in my Function Dim objUserFields As UserFields Dim dr As SqlClient.SqlDataReader Dim cnn As New SqlClient.SqlConnection(...) Dim cmd As New SqlClient.SqlCommand("usp_rt_get_userEmail", cnn) cnn.Open() cmd.Parameters.Add("@UserLogin", userLoginId) cmd.CommandType = CommandType.StoredProcedure Dim dt As New DataTable Dim da As New SqlDataAdapter(cmd) da.Fill(dt) [b]objUserFields.email_address = dt.Rows(0)("email_address") 'I get the error here [/b] Columns in Datatable are "email_address" and "User_login_id"... What am I missing?? Quote
eramgarden Posted December 6, 2005 Author Posted December 6, 2005 Thanks, I just figured it out when I saw your response. I was missing "new" from Dim objUserFields As UserFields Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.