Re: Parameterized query problem using Access Database in VS.NET2005
- From: "William \(Bill\) Vaughn" <billvaRemoveThis@xxxxxxxxxx>
- Date: Wed, 7 Mar 2007 13:34:46 -0800
Yes, of course. In your UI you let the user provide (or your code provides)
the rest of the wildcard expression. For example, if you were looking for
authors whose name begins with "B" you would pass an expression like
WHERE AuthorName LIKE 'B%'
You can also change the LIKE expression to a parameter so the SQL would look
like this:
WHERE AuthorName LIKE @NameWanted
or (in OLEDB-driven SQL parameters)
WHERE AuthorName LIKE ?
Your code would populate the Parameter with the Parameter value ("B" in this
case) concatenated with the wildcard character (%). The Parameter.Value
would then be "B%".
There are several other rules and tips that can help the SQL query optimizer
work more quickly (like ensuring that there is an index on the column and
that the wildcard is at the end of the expression) that I discuss in my
book.
hth
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
-----------------------------------------------------------------------------------------------------------------------
"JohnAdams" <u32320@uwe> wrote in message news:6ed77d8cf7392@xxxxxx
Paul Clement wrote:
For querying an Access database with the Jet OLEDB Provider you nee to use
the 'Like' keyword with
the '%' symbol.
Paul
~~~~
Microsoft MVP (Visual Basic)
With this code
SELECT CustomerNumber, Name, Address, City, State, Zip, Phone,
LastOrdDate, Inactive
FROM Customers
WHERE (Name LIKE '%')
it gives me all rows of the table with no ability to input what row(s) I
am
looking for.
That would work if I wanted all entries but I only want selected data, for
instance if I wanna look for those customer names that start with J in an
access query it would be J* and the criteria would be LIKE [" "] but this
does not work under the VS.net2005 SQL Select statements.
The way I have it set up is a search text box on the form and the user
inputs
the name or customer number and then hits search to start the query if
they
dont have the full name or customer number then they could only input part
of
it and search to get all those that fit the criteria.
any thoughts?
.
- Follow-Ups:
- Re: Parameterized query problem using Access Database in VS.NET2005
- From: JohnAdams via DotNetMonster.com
- Re: Parameterized query problem using Access Database in VS.NET2005
- References:
- Parameterized query problem using Access Database in VS.NET2005
- From: JohnAdams
- Re: Parameterized query problem using Access Database in VS.NET2005
- From: Paul Clement
- Re: Parameterized query problem using Access Database in VS.NET2005
- From: JohnAdams
- Parameterized query problem using Access Database in VS.NET2005
- Prev by Date: Re: Parameterized query problem using Access Database in VS.NET2005
- Next by Date: PARSE a Blank Space???
- Previous by thread: Re: Parameterized query problem using Access Database in VS.NET2005
- Next by thread: Re: Parameterized query problem using Access Database in VS.NET2005
- Index(es):
Relevant Pages
|