Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Searching for the beginning of a keyword - VB2010

Posted on 2011-03-14
4
Medium Priority
?
359 Views
Last Modified: 2012-05-11
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?
0
Comment
Question by:--TripWire--
  • 2
  • 2
4 Comments
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 35131054
I'm guessing:

myDataView.RowFilter = String.Format("Name LIKE '%{0}'", txtName.Text)
0
 
LVL 17

Accepted Solution

by:
Daniel Reynolds earned 100 total points
ID: 35131059
change it to

:
 myDataView.RowFilter = String.Format("Name LIKE '{0}%'", txtName.Text)
0
 
LVL 34

Assisted Solution

by:Paul MacDonald
Paul MacDonald earned 100 total points
ID: 35131063
Sorry, the other way:
myDataView.RowFilter = String.Format("Name LIKE '{0}%'", txtName.Text)
0
 
LVL 17

Expert Comment

by:Daniel Reynolds
ID: 35131075
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question