By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,363 Members | 1,470 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,363 IT Pros & Developers. It's quick & easy.

Using LIKE Operator

P: 39
Hi

If I retrive the data using the query

select Name from DoctorRegistration3 where Country='Indonesia' or AreaOfSpecialization='Cardiology' or Name like 'i%'


the answer is

Name
-----------
Imran
Sabri
Ghan


If I retrive the same query in .net by giving the same corresponding data as

"select Name from DoctorRegistration3 where Country='" + ddlCountry.SelectedItem.Text.ToString() + "' or AreaOfSpecialization='" + ddlDisease.SelectedItem.Text.ToString() + "' or Name like ''" + txtName.Text + "'%'";

then it shows the following error

Incorrect syntax near 'i'.

can anybody help me how to use the LIKE operator in .net
Jun 13 '08 #1
Share this Question
Share on Google+
4 Replies


deepuv04
Expert 100+
P: 227
Hi,

Use the following statement probably will work.

"select Name from DoctorRegistration3 where Country='" + ddlCountry.SelectedItem.Text.ToString() + "' or AreaOfSpecialization='" + ddlDisease.SelectedItem.Text.ToString() + "' or Name like '" + txtName.Text + "%'";
Jun 13 '08 #2

ck9663
Expert 2.5K+
P: 2,878
If deepuv's suggestion did not work for you, try displaying (using a prompt/messagebox or as text on your form) the entire query string as text. Copy it and paste it on your query analyzer/window. Then execute it. Your error would be more visible there.

Happy Coding.

-- CK
Jun 13 '08 #3

Atli
Expert 5K+
P: 5,058
Could this be caused by the extra ' in front of the % in the LIKE clause?
Jun 15 '08 #4

Delerna
Expert 100+
P: 1,134
Definitely, that part of the query would read as
Expand|Select|Wrap|Line Numbers
  1. or Name like 'i''%'       incorrect syntax near i
  2.  
instead of
Expand|Select|Wrap|Line Numbers
  1. or Name like 'i%'        correct
  2.  
Jun 15 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.