Searching for the beginning of a keyword - VB2010

Hello,

I have this line of code that searches for any name that is similar to the keyword typed in my text box.
myDataView.RowFilter = String.Format("Name LIKE '%{0}%'", txtName.Text)

Open in new window


But if I type 'A', it's going to return all the names that have the letter A in it.  I want all the names that begin with the letter A.  How is this done?
--TripWire--Asked:
Who is Participating?
 
Daniel ReynoldsConnect With a Mentor Software Applications Developer / IntegratorCommented:
change it to

:
 myDataView.RowFilter = String.Format("Name LIKE '{0}%'", txtName.Text)
0
 
Paul MacDonaldDirector, Information SystemsCommented:
I'm guessing:

myDataView.RowFilter = String.Format("Name LIKE '%{0}'", txtName.Text)
0
 
Paul MacDonaldConnect With a Mentor Director, Information SystemsCommented:
Sorry, the other way:
myDataView.RowFilter = String.Format("Name LIKE '{0}%'", txtName.Text)
0
 
Daniel ReynoldsSoftware Applications Developer / IntegratorCommented:
you will want the wildcard after your input value so {0}% will be the correct method.

if you do %{0} you will get anything ending in your input.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.