Hi, Sorry i need to ask for a help again.
I have a listview and a search button i want to populate my listview when i click a button to search
the field name "Last Name" for example i want to search "Sample" then it will populate my listbox with the result of the last name sample.

Show us what code you have so far and where it is falling over/ you are stuck...

And please provide details. For example, what is "Sample"? I'll assume that because you use Oledb in the title it is a database but you don't say what kind of database or provide some field names. Since you want to populate a listbox I can also infer that you expect more than one name to match. This generally means some type of wildcard search. So please provide somoe more information if you want a useful answer.

Hi sorry for the delayed.. I'm not feeling well yesterday but i'm feeling great now.

I'm using access as my database
I have a field name "First_Name" "Middle_Name" "Last_Name"

I want to search the Last_Name so it should be something like

    where Last_Name like Text1.text

and then it will populate my Listview all the data it find.

Here is an example using SQL server. It retrieves all records where au_lname starts with D. In Access the wildcard is "*" instead of "%". And you will have to use your own connection string.

Private Sub btnOleDB_Click(sender As System.Object, e As System.EventArgs) Handles btnOleDB.Click

    'OLEDB is more generic (can be used for different data sources) and supports
    'parameters but they are unnamed and positional

    ListView1.Items.Clear()

    Dim con As New OleDbConnection("Provider=SQLNCLI10;Server=.\SQLEXPRESS;Database=PUBS;Trusted_Connection=Yes;Connect Timeout=15;")
    Dim cmd As New OleDbCommand("", con)

    cmd.CommandText = "SELECT au_lname,au_fname,zip FROM authors WHERE au_lname like ?"
    cmd.Parameters.AddWithValue("@pan", "D%")

    con.Open()
    Dim rdr As OleDbDataReader = cmd.ExecuteReader()

    Do While rdr.Read
        ListView1.Items.Add(New ListViewItem({rdr.GetString(0), rdr.GetString(1), rdr.GetString(2)}))
    Loop

    rdr.Close()
    con.Close()

End Sub

What do u mean by
unnamed and positional

so if you were I..
what should you use??

The differences are explained here with examples. In a nutshell, using OleDb you have to add the parameters in the order in which they appear in the query. Using SqlClient you can add the parameters in any order. If you are using a SQL database you can use SqlClient (preferred). Otherwise you have to use OleDb. SqlClient is optimized for SQL databases.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.