Won't load Dependent Listbox
I am trying to get my program to populate a listbox with my dependent information from an access database. I am not getting any errors with my code, just won't load the list box any help would be helpful here is the code i have sofar.
Imports System.Data.OleDb
Public Class frmVHSEmployeeHB
'Public Declarations
Dim _EmployeeID As Integer = 0
Public Shared _VHSDB As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source:C:\Users\Autowolf80\Documents\CI11work\CIS 432\VHSEmployeeHB\vhs.accdb;Persist Security Info=False;"
Dim _ChildrenCount As Integer = 0
Dim _SOtherCount As Integer = 0
Public Shared _Report As Integer = 0
Private Sub EmployeesBindingNavigatorSaveItem_Click(sender As System.Object, e As System.EventArgs) Handles EmployeesBindingNavigatorSaveItem.Click
'Save the Record being added, reloads the Employee Data and sets focus to the last added record
Me.Validate()
Me.EmployeesBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.VhsDataSet)
Me.EmployeesTableAdapter.Fill(Me.VhsDataSet.Employ ees)
'Sets the Navi to last added Record
EmployeesBindingNavigator.BindingSource.MoveLast()
End Sub
Private Sub frmVHSEmployeeHB_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'this code was generated by the connection wizard, with and added try/catch block for a missing db file.
Try
Me.EmployeesTableAdapter.Fill(Me.VhsDataSet.Employ ees)
Catch ex As Exception
MsgBox("The database file is unavalable", , "Error")
Close()
End Try
End Sub
Private Sub mnuClose_Click(sender As System.Object, e As System.EventArgs) Handles mnuClose.Click
'Closes the Application
Close()
End Sub
Private Sub EmpIDTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EmpIDTextBox.TextChanged
' This event will action each time the Employee ID field is changed. This will load any dependents and selected Insurance coverage,
' clear update fields
_EmployeeID = Convert.ToInt32(EmpIDTextBox.Text)
' Call the LOAD DEPENDENTS routine
LoadDependents(_EmployeeID)
End Sub
Private Sub LoadDependents(ByVal EmployeeID As Integer)
'This event will display depends based on what employee record is currently being viewed in the navigator
'Error FLAG (initialized to FALSE)
Dim blnError As Boolean = False
Dim txtErrorMsg As String = "The system cannot load any records at this time"
'Clear the Dependent list
ClearDependent()
'Reload the Dependent list
'Data objects for Dependent dataset
Dim ds As New DataSet
Dim dt As New DataTable
Dim dr As DataRow
Dim txtDepClass As String = ""
'SQL SELECT statement for query
Dim strSQL As String = "Select [DepID], [DepClassCode], [DepFirstName], [DepLastName], [EmpID] from Dependents where [EmpID] = " & _EmployeeID
'Data Adapter to hold data
Dim da As New OleDb.OleDbDataAdapter(strSQL, _VHSDB)
'Try to fill the Dependent records
Try
da.Fill(ds, "dsdependents")
Catch excp As Exception
blnError = True
MsgBox(txtErrorMsg)
End Try
'check for errors
If Not blnError Then
dt = ds.Tables(0)
da.Dispose()
_ChildrenCount = 0
_SOtherCount = 0
' Load data
For Each dr In dt.Rows
lstDependents.Items.Add(dr(0).ToString() & "-" & dr(1).ToString() & "-" & dr(2).ToString() & " " & dr(3).ToString())
txtDepClass = dr(1).ToString
'Increment Spouse and Child Counts for Insurance Code verification
If txtDepClass = "C" Then
_ChildrenCount += 1
ElseIf txtDepClass = "S" Then
_SOtherCount += 1
End If
Next
End If
' MsgBox("Counts: Spouse-" & _SpouseCount.ToString() & " Child-" & _ChildCount.ToString())
End Sub
Private Sub ClearDependent()
'Clear the dependent lstbox
lstDependents.Items.Clear()
End Sub
End Class
|