Hello! I need a help from my code in filtering the male/female regular/contractual employees.
Scenario: I have 4 checkboxes the 'cbox' for contractual, 'rbox' for regular, 'mbox' for male and 'fbox' for female. What I wanted to happen is when I check 'mbox' it will display male employees in as well as 'fbox' for female and 'rbox' for regular employees and 'cbox' for contractual employees. I manage to make it work for single boxes filter but when I check 'cbox' together with 'fbox' that should display the female contractual employees only it displays both female regular and female contractual. Can someone check my code please.. Thank you.
Here's the code for my filter button:
Try
Dim choice As Boolean = True
Select Case choice
Case fbox.Checked = True And cbox.Checked = False
Using conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & System.Environment.CurrentDirectory & "\employeedb.mdb;")
conn.Open()
Dim command As New OleDbCommand("select * from employees where gender = 'Female'", conn)
Dim adapter As New OleDbDataAdapter
Dim dt As New DataTable
adapter.SelectCommand = command
adapter.Fill(dt)
DataGridView1.DataSource = dt
addDGV()
adapter.Dispose()
command.Dispose()
conn.Close()
End Using
Case fbox.Checked = True And rbox.Checked = False
Using conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & System.Environment.CurrentDirectory & "\employeedb.mdb;")
conn.Open()
Dim command As New OleDbCommand("select * from employees where gender = 'Female'", conn)
Dim adapter As New OleDbDataAdapter
Dim dt As New DataTable
adapter.SelectCommand = command
adapter.Fill(dt)
DataGridView1.DataSource = dt
addDGV()
adapter.Dispose()
command.Dispose()
conn.Close()
End Using
Case mbox.Checked = True And cbox.Checked = False
Using conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & System.Environment.CurrentDirectory & "\employeedb.mdb;")
conn.Open()
Dim command As New OleDbCommand("select * from employees where gender = 'Male'", conn)
Dim adapter As New OleDbDataAdapter
Dim dt As New DataTable
adapter.SelectCommand = command
adapter.Fill(dt)
DataGridView1.DataSource = dt
addDGV()
adapter.Dispose()
command.Dispose()
conn.Close()
End Using
Case mbox.Checked = True And rbox.Checked = False
Using conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & System.Environment.CurrentDirectory & "\employeedb.mdb;")
conn.Open()
Dim command As New OleDbCommand("select * from employees where gender = 'Male'", conn)
Dim adapter As New OleDbDataAdapter
Dim dt As New DataTable
adapter.SelectCommand = command
adapter.Fill(dt)
DataGridView1.DataSource = dt
addDGV()
adapter.Dispose()
command.Dispose()
conn.Close()
End Using
Case rbox.Checked = True And mbox.Checked = False
Using conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & System.Environment.CurrentDirectory & "\employeedb.mdb;")
conn.Open()
Dim command As New OleDbCommand("select * from employees where status = 'Regular'", conn)
Dim adapter As New OleDbDataAdapter
Dim dt As New DataTable
adapter.SelectCommand = command
adapter.Fill(dt)
DataGridView1.DataSource = dt
addDGV()
adapter.Dispose()
command.Dispose()
conn.Close()
End Using
Case rbox.Checked = True And fbox.Checked = False
Using conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & System.Environment.CurrentDirectory & "\employeedb.mdb;")
conn.Open()
Dim command As New OleDbCommand("select * from employees where status = 'Regular'", conn)
Dim adapter As New OleDbDataAdapter
Dim dt As New DataTable
adapter.SelectCommand = command
adapter.Fill(dt)
DataGridView1.DataSource = dt
addDGV()
adapter.Dispose()
command.Dispose()
conn.Close()
End Using
Case cbox.Checked = True And mbox.Checked = False
Using conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & System.Environment.CurrentDirectory & "\employeedb.mdb;")
conn.Open()
Dim command As New OleDbCommand("select * from employees where status = 'Contractual'", conn)
Dim adapter As New OleDbDataAdapter
Dim dt As New DataTable
adapter.SelectCommand = command
adapter.Fill(dt)
DataGridView1.DataSource = dt
addDGV()
adapter.Dispose()
command.Dispose()
conn.Close()
End Using
Case cbox.Checked = True And fbox.Checked = False
Using conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & System.Environment.CurrentDirectory & "\employeedb.mdb;")
conn.Open()
Dim command As New OleDbCommand("select * from employees where status = 'Contractual'", conn)
Dim adapter As New OleDbDataAdapter
Dim dt As New DataTable
adapter.SelectCommand = command
adapter.Fill(dt)
DataGridView1.DataSource = dt
addDGV()
adapter.Dispose()
command.Dispose()
conn.Close()
End Using
Case cbox.Checked = True And fbox.Checked = True
Using conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & System.Environment.CurrentDirectory & "\employeedb.mdb;")
conn.Open()
Dim command As New OleDbCommand("select * from employees where (status = 'Contractual') and (gender = 'Female')", conn)
Dim adapter As New OleDbDataAdapter
Dim dt As New DataTable
adapter.SelectCommand = command
adapter.Fill(dt)
DataGridView1.DataSource = dt
addDGV()
adapter.Dispose()
command.Dispose()
conn.Close()
End Using
Case cbox.Checked = True And mbox.Checked = True
Using conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & System.Environment.CurrentDirectory & "\employeedb.mdb;")
conn.Open()
Dim command As New OleDbCommand("select * from employees where status = 'Contractual' and gender = 'Male'", conn)
Dim adapter As New OleDbDataAdapter
Dim dt As New DataTable
adapter.SelectCommand = command
adapter.Fill(dt)
DataGridView1.DataSource = dt
addDGV()
adapter.Dispose()
command.Dispose()
conn.Close()
End Using
Case rbox.Checked = True And fbox.Checked = True
Using conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & System.Environment.CurrentDirectory & "\employeedb.mdb;")
conn.Open()
Dim command As New OleDbCommand("select * from employees where status = 'Regular' and gender = 'Female'", conn)
Dim adapter As New OleDbDataAdapter
Dim dt As New DataTable
adapter.SelectCommand = command
adapter.Fill(dt)
DataGridView1.DataSource = dt
addDGV()
adapter.Dispose()
command.Dispose()
conn.Close()
End Using
Case rbox.Checked = True And mbox.Checked = True
Using conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & System.Environment.CurrentDirectory & "\employeedb.mdb;")
conn.Open()
Dim command As New OleDbCommand("select * from employees where status = 'Regular' and gender = 'Male'", conn)
Dim adapter As New OleDbDataAdapter
Dim dt As New DataTable
adapter.SelectCommand = command
adapter.Fill(dt)
DataGridView1.DataSource = dt
addDGV()
adapter.Dispose()
command.Dispose()
conn.Close()
End Using
End Select
Catch ex As Exception
MessageBox.Show(ex.Message, "ERROR5", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try