help with function return datarow

Posted on 2009-02-19
Last Modified: 2012-08-13
I have a app that tries to get a datarow from a function.

Below is the subroutine that calls the function and the function

    Private Sub EmployeeNameComboBox_SelectionChangeCommitted _
    (ByVal sender As Object, ByVal e As System.EventArgs) Handles _
        ' Find and display territory descriptions for selected employee.

        Dim employeeIDint As Integer
        Dim employeeDataRow As DataRow
        Dim EmployeesRow As DataRow

        Dim territoryDescription As String
        Dim territoryDataRows As DataRow()

            With Me
                ' Get the employee ID of the selected employee.
                employeeIDint = Convert.ToInt16(EmployeeNameComboBox.SelectedValue)

                ' Find the row from the employee table for the selected employee ID.
                EmployeesRow = .aNORTHWNDataSet.Employees.FindByEmployeeID(employeeIDint)

                ' Retrieve an array of employee rows.
                territoryDataRows = employeeDataRow.GetChildRows( _

                ' Fill the list with the array of territory description rows.
                For Each territoryDataRow As DataRow In territoryDataRows
                    territoryDescription = territoryDataRow.GetParentRow _

            End With
        Catch ex As ApplicationException
        Catch ex As Exception
        End Try
    End Sub

The line that throws the exception is

                EmployeesRow = .aNORTHWNDataSet.Employees.FindByEmployeeID(employeeIDint)

Here's the function

 Public Function FindByEmployeeID(ByVal EmployeeID As Integer) As EmployeesRow
            Return CType(Me.Rows.Find(New Object() {EmployeeID}),EmployeesRow)
        End Function

I get object reference not set to an instance of an object
Question by:tremak
    LVL 14

    Expert Comment

    Where are you putting your breakpoint to trace this?   Does it actually get into the FindByEmployeeId function?  If it does, it would apear that Me.Rows is probably not declared.  If it does not make it into the function, Make sure that aNorthWndataset and the .employees exist.

    Author Comment

    I does not get into the function

    I'm fairly sure aNorthWndataset and .employees exists since intelli-sense will offer .employees as and option when you type in  EmployeesRow = .aNORTHWNDataSet.
    LVL 14

    Accepted Solution

    Just because intellisense offers this as an option does not mean that it has been created at runtime.   Where are you loading the dataset?

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    If you haven’t already, I encourage you to read the first article ( in my series to gain a basic foundation of R and R Studio.  You will also find the …
    The purpose of this article is to demonstrate how we can use conditional statements using Python.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now