Link to home
Start Free TrialLog in
Avatar of billyboy71
billyboy71

asked on

using the LIKE statement in a table adapter

Hi,

I am creating a table adapter which uses the SELECT query with a LIKE statement. However I can't seem to get the LIKE statement to work. I can get "=" statement to work but not the LIKE statement.

This does not work. It returns no values even when I enter the partial string correctly.
SELECT         episode, content, kewords, date, mpg
FROM             tbl_HappyStudy
WHERE         (content LIKE @content)

But this works fine. When I enter the exact string.
SELECT         episode, content, kewords, date, mpg
FROM             tbl_HappyStudyChinese
WHERE         (content = @content)

However, I would like to be able to search by a partial string. How can I use the 'LIKE' statement?

Thanks.
Peter
Avatar of vbturbo
vbturbo
Flag of Denmark image

Try this

SELECT         episode, content, kewords, date, mpg
FROM             tbl_HappyStudyChinese
WHERE         (content = ?)

vbturbo
Peter

Else checkout  here is a link working with the like operator http://msdn2.microsoft.com/en-us/library/069b0htd(VS.80).aspx
means

WHERE     (content LIKE '%' & @content & '%')
Avatar of billyboy71
billyboy71

ASKER

This does not seem to work using Visual Studio 2005 VB .net. I will get around the problem by adding '%' in the parameter the value itself.

So it will be.
SELECT         episode, content, kewords, date, mpg
FROM             tbl_HappyStudyChinese
WHERE         (content LIKE @content).

And then when I execute the query, I will enclose the value that I enter with  '%'

Thanks.
Glad you found your solution.

make a recommendation to PM to get a refund of the points
You solved you own problem. -)


btw. post your (descriped) solution here so others can benefit from it.

vbturbo
Basically, I will use the following SQL

SELECT         episode, content, kewords, date, mpg
FROM             tbl_HappyStudyChinese
WHERE         (content LIKE @content).

And in the query on the TableAdapter > Properties > Parameters >"Collection" , I set the DBType to "String".

Thanks.

Peter
ASKER CERTIFIED SOLUTION
Avatar of PashaMod
PashaMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial