Solved

Searching for the beginning of a keyword - VB2010

Posted on 2011-03-14
4
352 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:
xDJR1875 earned 25 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 25 total points
ID: 35131063
Sorry, the other way:
myDataView.RowFilter = String.Format("Name LIKE '{0}%'", txtName.Text)
0
 
LVL 17

Expert Comment

by:xDJR1875
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
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.​
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

914 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now