please, am new to, i have a project and i want to use a textbox as a search box to search through the data on the datagrid view on my form. please kindly assist

Recommended Answers

All 2 Replies

u can write in the textbox textchange event with the sql query using the like condition....

'Open Connection
   Dim myCommand As New OleDbCommand
   With myCommand
        .CommandText = "SELECT ID , (FirstName +' '+LastName) as Name FROM TableName where  ID like '" & Textbox1.Text & "%" + "' order by ID"
        .CommandType = CommandType.Text
        .Connection = Connection
   End With
   Dim dt As New DataTable
   With DatagridView1
        .AutoGenerateColumns = True
        .DataSource = dt
   End With
Catch ex As Exception
   MsgBox("Error in select query: " + ex.Message)
End Try
'Close Connection

there is another method to do this is
use this code at the textbox textchange event

dim con as new sqlconnection("connection string")
dim dt as new datatable
dim da as new sqldataadapter("select * from table1 where name like '" & textbox1.text & "%'",con)
datagridview1.datasource = dt

hope this will helps you ,


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.