Solved

Searching for the beginning of a keyword - VB2010

Posted on 2011-03-14
4
351 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 33

Expert Comment

by:paulmacd
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 33

Assisted Solution

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

705 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

19 Experts available now in Live!

Get 1:1 Help Now