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_Selec tionChange Committed _
(ByVal sender As Object, ByVal e As System.EventArgs) Handles _
EmployeeNameComboBox.Selec tionChange Committed
' 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(EmployeeNa meComboBox .SelectedV alue)
' Find the row from the employee table for the selected employee ID.
EmployeesRow = .aNORTHWNDataSet.Employees .FindByEmp loyeeID(em ployeeIDin t)
' Retrieve an array of employee rows.
territoryDataRows = employeeDataRow.GetChildRo ws( _
"EmployeeTerritories2Emplo yeesRelati on")
' Fill the list with the array of territory description rows.
.TerritoryListbox.Items.Cl ear()
For Each territoryDataRow As DataRow In territoryDataRows
territoryDescription = territoryDataRow.GetParent Row _
("EmployeeTerritories2Terr itoriesRel ation")!Te rritoryDes cription.T oString
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 .FindByEmp loyeeID(em ployeeIDin t)
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
Below is the subroutine that calls the function and the function
Private Sub EmployeeNameComboBox_Selec
(ByVal sender As Object, ByVal e As System.EventArgs) Handles _
EmployeeNameComboBox.Selec
' 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(EmployeeNa
' Find the row from the employee table for the selected employee ID.
EmployeesRow = .aNORTHWNDataSet.Employees
' Retrieve an array of employee rows.
territoryDataRows = employeeDataRow.GetChildRo
"EmployeeTerritories2Emplo
' Fill the list with the array of territory description rows.
.TerritoryListbox.Items.Cl
For Each territoryDataRow As DataRow In territoryDataRows
territoryDescription = territoryDataRow.GetParent
("EmployeeTerritories2Terr
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
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
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.
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.