Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (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 by eramgarden
Posted

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??

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...