search data in listview by using a textbox, this is my code sample cos i have been able to display data in access on listview so i want to perform a search function...
Imports System.Data
Imports System.Data.OleDb
Public Class Form9
Dim Passport As String = ""
Dim searching As Boolean
Dim sSql As String
Private Sub Form14_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With ListView1
.Clear()
.View = View.Details
.FullRowSelect = True
.GridLines = True
.Columns.Add("First Name", 200)
.Columns.Add("Middle Name", 200)
.Columns.Add("Last Name", 200)
.Columns.Add("Passport Number", 120)
.Columns.Add("Matric Number", 120)
.Columns.Add("Semester", 80)
.Columns.Add("Year", 50)
.Columns.Add("Course", 140)
End With
searching = False
Call fillListview()
' Load the data.
' Open the database.
Dim conn As OleDbConnection = GetDbConnection()
' Select records.
Dim cmd As New OleDbCommand( _
"SELECT * FROM Student ORDER BY FName ASC", conn)
Dim data_reader As OleDbDataReader = cmd.ExecuteReader()
Do While data_reader.Read()
Dim new_item As New ListViewItem(data_reader.Item("FName").ToString)
new_item.SubItems.Add(data_reader.Item("MName").ToString)
new_item.SubItems.Add(data_reader.Item("LName").ToString)
new_item.SubItems.Add(data_reader.Item("Passport").ToString)
new_item.SubItems.Add(data_reader.Item("Matric").ToString)
new_item.SubItems.Add(data_reader.Item("Semester").ToString)
new_item.SubItems.Add(data_reader.Item("Year").ToString)
new_item.SubItems.Add(data_reader.Item("Course").ToString)
ListView1.Items.Add(new_item)
Debug.WriteLine(new_item.Text & " : " & _
new_item.SubItems(0).Text & ", " & _
new_item.SubItems(1).Text & ", " & _
new_item.SubItems(2).Text & ", " & _
new_item.SubItems(3).Text & ", " & _
new_item.SubItems(4).Text & ", " & _
new_item.SubItems(5).Text & ", " & _
new_item.SubItems(6).Text & ", " & _
new_item.SubItems(7).Text)
Loop
' Close the connection.
conn.Close()
End Sub
' Open the database.
Private Function GetDbConnection() As OleDbConnection
' Compose the database file name.
' Modify this if the database is somewhere else.
Dim database_name As String = Application.StartupPath()
database_name = database_name.Substring(0, database_name.LastIndexOf("\"))
database_name = database_name & "\linton.mdb"
' Compose the connect string.
Dim connect_string As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & database_name
' Open a database connection.
Dim conn As New OleDbConnection(connect_string)
conn.Open()
' Return the connection.
Return conn
End Function