Hi All,
I was able to solve my issue. I created individual functions for each date scenario to the filter the data for the specific date range and return a result to the datagridview. Then for each radio button, I called the individual function and bind the function to the datagridview. The source code is show below: -
Private Function GetEmployeeListToday() As DataTable
Dim dtEmployeeToday As New DataTable
Dim adapter As New MySqlDataAdapter("SELECT * FROM mydatabase.Employees WHERE DATE(Now())", connection)
adapter.Fill(dtEmployeeToday)
Return dtEmployeeToday
End Function
Private Sub rdoToday_CheckedChanged(sender As Object, e As EventArgs) Handles rdoToday.CheckedChanged
Me.BindingSource1.DataSource = GetEmployeeListToday()
Me.EmployeeDataGridView.DataSource = Me.BindingSource1
End Sub
Private Function GetEmployeeListTomorrow() As DataTable
Dim dtEmployeeTomorrow As New DataTable
Dim adapter As New MySqlDataAdapter("SELECT * FROM mydatabase.Employees WHERE DATE(EmployeeDate) = DATE(NOW() - INTERVAL 1 DAY)", connection)
adapter.Fill(dtEmployeeTomorrow)
Return dtEmployeeTomorrow
End Function
Private Sub rdoTomorrow_CheckedChanged(sender As Object, e As EventArgs) Handles rdoTomorrow.CheckedChanged
Me.BindingSource1.DataSource = GetEmployeeListTomorrow()
Me.EmployeeDataGridView.DataSource = Me.BindingSource1
End Sub
Private Function GetEmployeeListYesterday() As DataTable
Dim dtEmployeeYesterday As New DataTable
Dim adapter As New MySqlDataAdapter("SELECT * FROM mydatabase.Employees WHERE SUBDATE(NOW(),1)", connection)
adapter.Fill(dtEmployeeYesterday)
Return dtEmployeeYesterday
End Function
Private Sub rdoYesterday_CheckedChanged(sender As Object, e As EventArgs) Handles rdoYesterday.CheckedChanged
Me.BindingSource1.DataSource = GetEmployeeListYesterday()
Me.EmployeeDataGridView.DataSource = Me.BindingSource1
End Sub
Private Function GetEmployeeListNextSevenDays() As DataTable
Dim dtEmployeeNextSevenDays As New DataTable
Dim adapter As New MySqlDataAdapter("SELECT * FROM mydatabase.Employees WHERE DATE(EmployeeDate) = DATE(NOW() - INTERVAL 7 DAY)", connection)
adapter.Fill(dtEmployeeNextSevenDays)
Return dtEmployeeNextSevenDays
End Function
Private Sub rdoNext7days_CheckedChanged(sender As Object, e As EventArgs) Handles rdoNext7days.CheckedChanged
Me.BindingSource1.DataSource = GetEmployeeListNextSevenDays()
Me.EmployeeDataGridView.DataSource = Me.BindingSource1
End Sub
Private Function GetEmployeeListLastSevenDays() As DataTable
Dim dtEmployeeLastSevenDays As New DataTable
Dim adapter As New MySqlDataAdapter("SELECT * FROM mydatabase.Employees WHERE SUBDATE(NOW(),7)", connection)
adapter.Fill(dtEmployeeLastSevenDays)
Return dtEmployeeLastSevenDays
End Function
Private Sub rdoLast7days_CheckedChanged(sender As Object, e As EventArgs) Handles rdoLast7days.CheckedChanged
Me.BindingSource1.DataSource = GetEmployeeListLastSevenDays()
Me.EmployeeDataGridView.DataSource = Me.BindingSource1
End Sub