Start New Discussion Reply to this Discussion search box
please, am new to vb.net, 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
10 Months Ago
Last Updated
Related Article: Using Search Box in another form
is a solved VB.NET discussion thread by kenomote that has 7 replies, was last updated 6 months ago and has been tagged with the keywords: search, box, textbox, database.
tracemic
Newbie Poster
1 post since Jul 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
u can write in the textbox textchange event with the sql query using the like condition....
'Open Connection
Try
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
dt.Load(myCommand.ExecuteReader)
With DatagridView1
.AutoGenerateColumns = True
.DataSource = dt
End With
Catch ex As Exception
MsgBox("Error in select query: " + ex.Message)
End Try
'Close Connection
poojavb
Posting Pro
524 posts since Nov 2011
Reputation Points: 39
Solved Threads: 77
Skill Endorsements: 5
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
con.open()
dim da as new sqldataadapter("select * from table1 where name like '" & textbox1.text & "%'",con)
da.fill(dt)
datagridview1.datasource = dt
con.close
hope this will helps you ,
Regards
M.Waqas Aslam
Master Poster
747 posts since Aug 2011
Reputation Points: 50
Solved Threads: 121
Skill Endorsements: 2
© 2013 DaniWeb® LLC
Page rendered in 0.3066 seconds
using 2.68MB