Link to home
Start Free TrialLog in
Avatar of tremak
tremak

asked on

help with vb.net function return datarow

I have a vb.net 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 _
    EmployeeNameComboBox.SelectionChangeCommitted
        ' 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()

        Try
            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( _
                  "EmployeeTerritories2EmployeesRelation")

                ' Fill the list with the array of territory description rows.
                .TerritoryListbox.Items.Clear()
                For Each territoryDataRow As DataRow In territoryDataRows
                    territoryDescription = territoryDataRow.GetParentRow _
                    ("EmployeeTerritories2TerritoriesRelation")!TerritoryDescription.ToString
                Next

            End With
        Catch ex As ApplicationException
            MessageBox.Show(ex.Message)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        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
Avatar of jjardine
jjardine
Flag of United States of America image

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.
Avatar of tremak
tremak

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of jjardine
jjardine
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial