Hello Guys! I am using listview. i want to search using textbox records from the database and display the searched records in listview. i read some post here with same/like mine but they're using datagrid. :|

ListBox1.Items.Clear()
        Try
            con.Open()

            Dim da As New SqlDataAdapter("select * from student where id="+Me.TextBox1.Text, db.con)
            Dim ds As New DataSet
            da.Fill(ds, "1")

                   For i As Integer = 0 To ds.Tables("1").Rows.Count - 1
                Me.ListBox1.Items.Add(ds.Tables("1").Rows(i)(0) + "  -  " + ds.Tables("1").Rows(i)(1))
            Next

        Catch ex As Exception
            MsgBox("Error : " + ex.Message)
        Finally
con.Close()
        End Try

Here con is a SqlConnection object...

try this....

Hello Guys! I am using listview. i want to search using textbox records from the database and display the searched records in listview. i read some post here with same/like mine but they're using datagrid. :|

Private Sub Button3_Click_1(sender As System.Object, e As System.EventArgs) Handles Button3.Click
        L1.Items.Clear()

        mysql = "SELECT * FROM student where ln like '" & TextBox5.Text & "%'"
        Dim ream As OleDbDataReader
        comg = New OleDbCommand(mysql, conn)
        ream = comg.ExecuteReader

        While ream.Read
            With L1
                .Items.Add(ream("id"))
                With .Items(.Items.Count - 1).SubItems
                    .Add(ream("fn"))
                    .Add(ream("mi"))
                    .Add(ream("ln"))
                End With
            End With
        End While
    End Sub
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.