I'm stuck with coding to filter my search data in datagrid.
I'm using datagrid to view three different table in my database.
I have three button to view the tables. When I click on one of the table, show payment (it will show payment table) and from there I will filter the data base on name or id number.
But I don't know how to proceed from show button into filter data in my database.
'Show Data in DataGrid
Private Sub showpdbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles showpdbtn.Click
Dim schomasys As New DataTable()
dataAdapter = New OleDbDataAdapter("SELECT * FROM PersonalDetails", conn)
dataAdapter.Fill(schomasys)
dgrid.DataSource = schomasys
End If
End Sub
Private Sub showEdubtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles showEdubtn.Click
Dim schomasys As New DataTable()
dataAdapter = New OleDbDataAdapter("SELECT * FROM EducationRecords", conn)
dataAdapter.Fill(schomasys)
dgrid.DataSource = schomasys
End Sub
Private Sub showpbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles showpbtn.Click
Dim schomasys As New DataTable()
dataAdapter = New OleDbDataAdapter("SELECT * FROM payment", conn)
dataAdapter.Fill(schomasys)
dgrid.DataSource = schomasys
End Sub
Private Sub searchpbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles searchbtn.Click
Dim showpdbtn As Boolean = False
Dim showEdubtn As Boolean = False
Dim showpbtn As Boolean = False
connection.Open()
'command.Connection = connection
'command.CommandType = CommandType.Text
If showpdbtnClick = True Then
' SQL Statement to search for either Name or ID Number
Dim sqlsearch As String
sqlsearch = "SELECT * FROM PersonalDetails"
Try
If Me.combosearch.Text = "Name" Then
sqlsearch = sqlsearch & " where sname like '%" & Me.txtsearch.Text & "%'"
Else
sqlsearch = sqlsearch & " where idnumber =" & Me.txtsearch.Text
End If
' Once again we execute the SQL statements against our DataBase
Dim adapter As New OleDbDataAdapter(sqlsearch, connection)
' Shows the records and updates the DataGridView
Dim schomasys As New DataTable("PersonalDetails")
dataAdapter.Fill(schomasys)
dgrid.DataSource = schomasys
Catch ex As Exception
MsgBox(ErrorToString)
Finally
connection.Close()
End Try
If showEdubtn_Click() = True Then
' SQL Statement to search for either Name or ID Number
Dim sqlsearch As String
sqlsearch = "SELECT *FROM EducationRecords"
Try
If Me.combosearch.Text = "Name" Then
sqlsearch = sqlsearch & " where sname like '%" & Me.txtsearch.Text & "%'"
Else
sqlsearch = sqlsearch & " where idnumber =" & Me.txtsearch.Text
End If
' Once again we execute the SQL statements against our DataBase
Dim adapter As New OleDbDataAdapter(sqlsearch, connection)
' Shows the records and updates the DataGridView
Dim schomasys As New DataTable("PersonalDetails")
dataAdapter.Fill(schomasys)
dgrid.DataSource = schomasys
Catch ex As Exception
MsgBox(ErrorToString)
Finally
connection.Close()
End Try
If showpbtn_Click() = True Then
' SQL Statement to search for either Name or ID Number
Dim sqlsearch As String
sqlsearch = "SELECT * FROM payment"
Try
If Me.combosearch.Text = "Name" Then
sqlsearch = sqlsearch & " where sname like '%" & Me.txtsearch.Text & "%'"
Else
sqlsearch = sqlsearch & " where idnumber =" & Me.txtsearch.Text
End If
' Once again we execute the SQL statements against our DataBase
Dim adapter As New OleDbDataAdapter(sqlsearch, connection)
' Shows the records and updates the DataGridView
Dim schomasys As New DataTable("PersonalDetails")
dataAdapter.Fill(schomasys)
dgrid.DataSource = schomasys
Catch ex As Exception
MsgBox(ErrorToString)
Finally
connection.Close()
End Try
Else
MsgBox("Record not found!")
End If
Else
MsgBox("Record not found!")
End If
Else
MsgBox("Record not found!")
End If
End Sub

New Topic/Question
Reply



MultiQuote








|