Selasa, 28 Januari 2014

Advance filtering using 2 TextBox

Step 1 >>>> add two textbox into your form. see image below for your reference.
Figure 1.0














Step 2 >>>> double click your first textbox and paste this code and change it function to TextChanged;

       str = "select * from info where Lname like %" & TextBox1.Text & "% and Fname like %" & TextBox2.Text & "%"
        con.Open()
        cmd = New MySqlCommand(str, con)
        dr = cmd.ExecuteReader()
        ListView1.Items.Clear()

        Do While dr.Read()
            Dim lv As ListViewItem = ListView1.Items.Add(dr.Item("Lname").ToString())
            lv.SubItems.Add(dr.Item("Fname").ToString())
            lv.SubItems.Add(dr.Item("Dept").ToString())

        Loop
        con.Close()
        cmd.Dispose()

        dr.Close()

Step 3 >>>> double click your second textbox and paste this code and change it function to TextChanged;

   str = "select * from info where Lname like %" & TextBox1.Text & "% and Fname like %" & TextBox2.Text & "%"
        con.Open()
        cmd = New MySqlCommand(str, con)
        dr = cmd.ExecuteReader()
        ListView1.Items.Clear()

        Do While dr.Read()
            Dim lv As ListViewItem = ListView1.Items.Add(dr.Item("Lname").ToString())
            lv.SubItems.Add(dr.Item("Fname").ToString())
            lv.SubItems.Add(dr.Item("Dept").ToString())

        Loop
        con.Close()
        cmd.Dispose()

        dr.Close()

in this tutorial i use two Like filtering to make it easier to find the data that you want.

0 komentar to “Advance filtering using 2 TextBox”

Posting Komentar

 

Internet Android App Copyright © 2016 -- Powered by Blogger