We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,272 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
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

3
Contributors
2
Replies
22 Hours
Discussion Span
10 Months Ago
Last Updated
4
Views
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

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.3066 seconds using 2.68MB