Using 'like' in TableAdapter SQL statement with parameter

G

Guest

I am trying to create a query in a TableAdapter that looks like this:

SELECT partnumber,description FROM parts WHERE description LIKE '%' + ? + '%'

The idea is that the query will find any parts that contain the description
fragment passed in as a parameter. I'm not sure how to go about the " LIKE
'%' + ? + '%' " part, though. It's an OLEDB data source, thus the ? as the
parameter designation. But are then any suggestions?

Thanks,
Cliffe
 
W

William \(Bill\) Vaughn

I would use the Query Builder to generate the right syntax. You can specify
filter criteria in the designer that will build the right SQL.

hth

--
William (Bill) Vaughn
President and Founder Beta V Corporation
Redmond, WA
(425) 556-9205
Microsoft MVP, Author, Mentor
Microsoft MVP
 
Joined
Mar 22, 2006
Messages
16
Reaction score
0
Forgive me if the TableAdapter is new to .NET 2.0, I'm not familiar with it.

I think all you want to do is create a parameter object and add it to the commands parameters collection. I'm not sure how that works exactly with unnamed parameters.
 
G

Guest

SELECT partnumber,description FROM parts WHERE description LIKE ?

then for teh value of your parameter, use any of the following:
somevalue
%someValue
somevalue%
%somevalue%

place the %'s inside of the parameter value, not inside of the sql literal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top