Public Function FillGrid(ByVal bw As BackgroundWorker, ByVal sleepPeriod As Integer) As Boolean
'Fill the table with the items that expire with in the month and year the user picks in the datetimepicker
Dim dtExpired As Date
Dim dtbegin As Date
Dim dtend As Date
Dim strfilepath As String
While Not bw.CancellationPending
Dim [exit] As Boolean = False
Try
Dim path As String
path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
'Extract the path returned minus the file:\ that is placed at the begining.
path = Mid(path, 7)
If My.Computer.FileSystem.FileExists(path & "\Source.txt") Then
' Add code to read text from a file.
' Create an instance of StreamReader to read from a file.
Using sr As StreamReader = New StreamReader("Source.txt")
Dim line As String
' Read and display the lines from the file until the end
' of the file is reached.
'Do
line = sr.ReadLine()
strfilepath = line
'Loop Until line Is Nothing
End Using
'Get the date the user picked.
dtExpired = dtDate
'Now get the month and year to be used as the begin date
dtbegin = dtExpired.Month & "/1/" & dtExpired.Year
dtend = dtbegin.AddMonths(1)
cn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Temp Projects\PSNA Application\PSNA2\PSNA\PSNA\bin\PSNA Application Expiration.accdb;") '" & strfilepath & ";")
'provider to be used when working with access database
cn.Open()
cmd = New OleDbCommand("SELECT [Program Title], [Contact Hours], [Start Date], [Expiration Date], Presenter, [Type of Program], Method FROM Programs WHERE ([Expiration Date] BETWEEN @date1 AND @date2)", cn)
cmd.Parameters.Add(New OleDbParameter("@date1", OleDbType.Date)).Value = dtbegin
cmd.Parameters.Add(New OleDbParameter("@date2", OleDbType.Date)).Value = dtend
dr = cmd.ExecuteReader
If dr.HasRows = True Then
'Add the return data as a new source to the binding source
bs.DataSource = dr
Else
MsgBox("There are no records that match your criteria.", MsgBoxStyle.OkOnly, "No Matches")
End If
dr.Close()
cn.Close()
Else
MsgBox("The file Source.txt is missing.", MsgBoxStyle.OkOnly, "File Missing")
End If
Catch ex As Exception
Dim strerror As String
strerror = ex.Message.ToString
MsgBox(ex.Message.ToString, MsgBoxStyle.OkOnly, "Error")
System.Diagnostics.Debug.WriteLine(strerror)
End Try
[exit] = True
If [exit] Then
Exit While
End If
End While
Return True
End Function