?
Solved

Double quote in the SQL statement

Posted on 2005-03-10
3
Medium Priority
?
433 Views
Last Modified: 2010-04-16
I have the following code
OleDbCommand cmd = new OleDbCommand("select * from Table where Name LIKE '%\"SARA\"%' ", con);
OleDbDataReader reader = cmd.ExecuteReader();

I have a recored containing blabla"SARA"blabla but my OLEDB command when it is executed doesn't return anything. How should I handle double quotes in a SQL statement.

Thank you
0
Comment
Question by:MihaelaS
3 Comments
 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 375 total points
ID: 13507007
try using parameter
OleDbCommand cmd = new OleDbCommand("select * from Table where Name LIKE :p", con);
cmd.Parameters.Add("p",OleDbType.VarChar,30).Value ="\"SARA\"%"
OleDbDataReader reader = cmd.ExecuteReader();

it should work fine, also using parameters faster with some db like oracle and sql server

Regards,
Mohammed
0
 
LVL 9

Expert Comment

by:Wim_Bl
ID: 13508754
Hi,

since you can use single quotes by putting 2 of them in your statement, I would suggest doing the same for double quotes, so
use ""SARA""

greetings
0
 
LVL 9

Expert Comment

by:sun4sunday
ID: 13515798

How to Use Variables (managing single & double quotes) in .Net SQL Statements

http://aspnet101.com/aspnet101/tutorials.aspx?id=2

sun4sunday
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses
Course of the Month9 days, 13 hours left to enroll

612 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question