I want to filter my datas which are stored in MySql database with combining multiple checkbox and textbox queries. You can find the screenshot of the form here:
SEARCH FORM:

TABLES:
PROJECTS TABLE

DETAILS TABLE

PS: Only ID field in Projects table is unique!
If user writes in any of these three textboxes than the rest of the textbox will getting empty. Currently it works fin with textboxes. I want to combine the seach criteria with the checkboxes.
Assume that user writes in TEXTBOX1 and selects FAS, VAPA and ACC from checkboxes than the result should be listed in my listview box.
Here's the codes I've come so far :
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If TextBox1.Text = "" And TextBox2.Text = "" And TextBox3.Text = "" Then
MsgBox("Bir arama kriteri girin!", MsgBoxStyle.Critical, "UYARI!")
Exit Sub
End If
ListView1.Items.Clear()
If TextBox1.Text <> "" Then
Dim cmd As New MySqlCommand
Dim ad As New MySqlDataAdapter
Dim projeadi As String = "select projects.ID, projects.PROJEADI, projects.TEKLIFFIRMA, details.ID, details.MARKA from projects INNER JOIN details ON projects.ID = details.ID WHERE PROJEADI='" & TextBox1.Text & "';"
Dim tbl As New DataTable
Dim i As Integer
With cmd
.CommandText = projeadi
.Connection = con
End With
With ad
.SelectCommand = cmd
.Fill(tbl)
End With
For i = 0 To tbl.Rows.Count - 1
With ListView1
.Items.Add(tbl.Rows(i)("ID"))
With .Items(.Items.Count - 1).SubItems
.Add(tbl.Rows(i)("PROJEADI"))
.Add(tbl.Rows(i)("TEKLIFFIRMA"))
.Add(tbl.Rows(i)("MARKA"))
End With
End With
Next
ElseIf TextBox2.Text <> "" Then
Dim cmd As New MySqlCommand
Dim ad As New MySqlDataAdapter
Dim tekliffirma As String = "select projects.ID, projects.PROJEADI, projects.TEKLIFFIRMA, details.ID, details.MARKA from projects INNER JOIN details ON projects.ID = details.ID WHERE TEKLIFFIRMA='" & TextBox2.Text & "';"
Dim tbl As New DataTable
Dim i As Integer
With cmd
.CommandText = tekliffirma
.Connection = con
End With
With ad
.SelectCommand = cmd
.Fill(tbl)
End With
For i = 0 To tbl.Rows.Count - 1
With ListView1
.Items.Add(tbl.Rows(i)("ID"))
With .Items(.Items.Count - 1).SubItems
.Add(tbl.Rows(i)("PROJEADI"))
.Add(tbl.Rows(i)("TEKLIFFIRMA"))
.Add(tbl.Rows(i)("MARKA"))
End With
End With
Next
ElseIf TextBox3.Text <> "" Then
Dim cmd As New MySqlCommand
Dim ad As New MySqlDataAdapter
Dim marka As String = "select projects.ID, projects.PROJEADI, projects.TEKLIFFIRMA, details.ID, details.MARKA from projects INNER JOIN details ON projects.ID = details.ID WHERE MARKA='" & TextBox3.Text & "';"
Dim tbl As New DataTable
Dim i As Integer
With cmd
.CommandText = marka
.Connection = con
End With
With ad
.SelectCommand = cmd
.Fill(tbl)
End With
For i = 0 To tbl.Rows.Count - 1
With ListView1
.Items.Add(tbl.Rows(i)("ID"))
With .Items(.Items.Count - 1).SubItems
.Add(tbl.Rows(i)("PROJEADI"))
.Add(tbl.Rows(i)("TEKLIFFIRMA"))
.Add(tbl.Rows(i)("MARKA"))
End With
End With
Next
End If
Please advise.
Thank you.
Oguz
CheckBox.CheckedChangedevent.