Using 'like' in TableAdapter SQL statement with parameter

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
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.
 
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
 
Back
Top