[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1367
  • Last Modified:

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 _
        ' 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
  • 2
1 Solution
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.
tremakAuthor Commented:
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.
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now