I am a newbie in programming and I just learn programming by watching tutorial videos and reading articles. I have been searching for this but failed to find it. As a newbie like me we really appreciate any kind of help from the expert like you guys.
I created a form and use datagridview where my database data goes and i am able to search using textbox and the Button that I created. But I want to put a Filter on it so If a user wants to search the IT Staff from japan, so they choose Country in the first combobox and japan in 2nd combobox2. now they want to search IT Staff from japan whose status is Hired, so they enter Hired in the second text box , and the data grid shows IT Staff from japan whose status is Hired.
This is my Table
Position Country Status
IT Staff Japan Hired
Teacher Germany Not Hired
IT Staff Mexico Hired
when i type on my textbox "Hired" in my Datagridview shows
IT Staff Japan Hired
IT Staff Mexico Hired
I only want to show in my datagridview all IT Staff in japan whose hired.
What I have tried:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If ComboBox1.Text = "Country" Then
If ComboBox2.Text = "Japan" Then
Status()
End If
End If
End Sub
Public Sub Status()
Try
Dim sCon As String = String.Format("Provider= Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\db.accdb")
Dim str As String = "SELECT * FROM dbtable WHERE Status = @S"
Dim dt As New DataTable
Using con1 As OleDbConnection = New OleDbConnection(sCon)
con1.Open()
Using cmd1 As OleDbCommand = New OleDbCommand(str, con1)
With cmd1.Parameters
.Add("@S", OleDbType.VarChar).Value = TextBox1.Text
End With
Dim adp As New OleDbDataAdapter(cmd1)
adp.Fill(dt)
DataGridView1.DataSource = dt
End Using
con1.Close()
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub