Auto search through textbox and dynamically populate datagrid

rajeevanand

New member
Joined
Sep 9, 2012
Messages
1
Programming Experience
Beginner
i have posted this on Auto search through textbox and dynamically populate datagrid also

hello everyonecan anyone help on this.
i have a table with column's (itemcode, itemname, price) on the vb form i have one search field (textbox1) and datagrid.
i have data as
itemcode itemname price
1234 apple 10
1235 orange 12
1345 grapes 15
1356 banana 15
1357 apricot 25
2345 strawberry 20
2346 guava 10
now what i am trying is, when i start to type 1 then grid should show all data's starting with 1 and as i type 12 then it should filter only remaining data with itemcode starting with 12... and so on. something similar to google search as we type query above matching items change in the page.
i hope i am able to get my point through..
simple search i am able to do i.e. when whole string match's with itemcode it shows the details in gridview. code i m using on change event of textbox is Code:

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
'i have opened connection above
cn.Open() Dim a As New OleDbDataAdapter("Select * from Item where ItemName = ' " & TextBox1.Text & "'", cn)
Dim b As New DataSet
a.Fill(b, "Item")
DataGridView2.DataSource = b.Tables(0)
cn.Close()
End Sub

thanx in advance
 
Last edited:
Hi,

The thing that you are missing is the "wildcard" for the search criteria in the where clause of your sql statement. The wildcard character that you need to add depends on which database you are using.

In SQL Server this is the "%" character and in MS Access this is the "*" character.

Therefore, your sql string should read something like "Select * from Item where ItemName = ' " & TextBox1.Text & "%'" or "Select * from Item where ItemName = ' " & TextBox1.Text & "*'"

Hope this helps.
 
Back
Top