Results 1 to 6 of 6

Thread: reference to a non-shared member requries an object reference

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    2

    Exclamation reference to a non-shared member requries an object reference

    Can someone tell me what is the matter with this code:

    Code:
        Public Sub showdataset()
            For Each dt As DataTable In dsEvents.Tables
                Response.Write("<table border='1'>" & vbCrLf)
                For Each row As DataRow In Table.Rows
                    Response.Write("<tr>" & vbCrLf)
                    For Each dc As DataColumn In Table.Columns
                        Response.Write("<td>" & row(dc).ToString & "</td>" & vbCrLf)
                    Next
                    Response.Write("</tr>" & vbCrLf)
                Next
                Response.Write("</table>" & vbCrLf)
            Next
        End Sub

  2. #2
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: reference to a non-shared member requries an object reference

    Do you maybe want dt.Rows instead?

  3. #3
    Hyperactive Member
    Join Date
    Feb 2009
    Posts
    258

    Re: reference to a non-shared member requries an object reference

    What error are you getting, and where? Give us a clue to go on, okay?

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    2

    Re: reference to a non-shared member requries an object reference

    @minitech
    Yes, when I changed Table.rows to dt.rows and Table.columns to dt.columns, the problem went away.

    But a new problem shows up now.
    Code:
        Public Sub showdataset()
            For Each dt As DataTable In dsEvents.Tables
                Response.Write("<table border='1'>" & vbCrLf)
                For Each row As DataRow In dt.Rows
                    Response.Write("<tr>" & vbCrLf)
                    For Each dc As DataColumn In dt.Columns
                        Response.Write("<td>" & row(dc).ToString & "</td>" & vbCrLf)
                    Next
                    Response.Write("</tr>" & vbCrLf)
                Next
                Response.Write("</table>" & vbCrLf)
            Next
        End Sub
    I've tried passing the Dataset as a referenced argument to this Sub, but that was no help.
    To be more specific, the exact error is:
    System.NullReferenceException: Object reference not set to an instance of an object.
    Last edited by taersious; Feb 8th, 2010 at 07:54 PM. Reason: Problem not solved.

  5. #5

    Re: reference to a non-shared member requries an object reference

    Sounds like an object isn't initialized, more specifically whatever dsEvents is. (dataTable I'm assuming)

  6. #6
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: reference to a non-shared member requries an object reference

    Quote Originally Posted by taersious View Post
    @minitech
    Yes, when I changed Table.rows to dt.rows and Table.columns to dt.columns, the problem went away.

    But a new problem shows up now.
    Code:
        Public Sub showdataset()
            For Each dt As DataTable In dsEvents.Tables
                Response.Write("<table border='1'>" & vbCrLf)
                For Each row As DataRow In dt.Rows
                    Response.Write("<tr>" & vbCrLf)
                    For Each dc As DataColumn In dt.Columns
                        Response.Write("<td>" & row(dc).ToString & "</td>" & vbCrLf)
                    Next
                    Response.Write("</tr>" & vbCrLf)
                Next
                Response.Write("</table>" & vbCrLf)
            Next
        End Sub
    I've tried passing the Dataset as a referenced argument to this Sub, but that was no help.
    To be more specific, the exact error is:
    Assuming the underline (and red) dsEvents is where the error is that you're telling us is a null reference exception, it's say dsEvents is null (equal to 'Nothing') when it hits that line. You should probably initialize it (dsEvents = New DataSet) at some point before using it. You might also want to fill it before using it too.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width