Wrox Programmer Forums
|
.NET 4 and Visual Studio 2010 General Discussions For discussing anything about .NET 4, WPF, WCF, the rest of the .NET 4 Framework, and Visual Studio 2010 that isn't about a specific Wrox book. Please post code questions about a specific language (C#, VB, ASP.NET, etc) in the correct language forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET 4 and Visual Studio 2010 General Discussions section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 5th, 2012, 08:00 PM
Registered User
 
Join Date: Nov 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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





Similar Threads
Thread Thread Starter Forum Replies Last Post
ListBox Load Every Visible Cell ptrussell2009 Excel VBA 2 February 22nd, 2016 05:42 AM
Load a listbox from a word file list Davefeno VB.NET 1 June 22nd, 2011 01:15 AM
dependent drop downs p2pMember ASP.NET 1.0 and 1.1 Professional 0 July 19th, 2006 05:25 AM
Look up value dependent on 2 other variables nkrukovsky Excel VBA 1 September 22nd, 2004 09:51 PM
dependent dropdown lists vivshah VS.NET 2002/2003 1 March 29th, 2004 05:25 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.