?
Solved

Double quote in the SQL statement

Posted on 2005-03-10
3
Medium Priority
?
430 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

770 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