Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am passing some query like this:
C#
"select * from Item where Item_Name like '" + GridViewItem.Rows[0].Cells[1].ToString() + "'";

Item Name contains a single quote, so when I am passing the above error is coming.
Suggest me some answers...
Thank You...
Posted
Updated 8-Oct-13 21:25pm
v2
Comments
CodeBlack 9-Oct-13 3:09am    
Can you post your code ?

You should be using Parameter queries instead of string concatenation.

a) it solves the issue with strings having quotes in them.
b) helps secure your queries against SQL Injection attacks.

There are alot of resources on this site and on google explaining how to create a paramterized query.
 
Share this answer
 
use something like:
C#
GridViewItem.Rows[0].Cells[1].ToString().Replace("'","''") 

or maybe
C#
GridViewItem.Rows[0].Cells[1].ToString().Replace("'","\'")


I'm not really sure because of the many sql languages, but you can easily try one of these and see what happens
 
Share this answer
 
Comments
Shibasankar 9-Oct-13 3:15am    
I am doing transaction management process. Will this formula work there for three or more transactions?
Shibasankar 9-Oct-13 3:37am    
Yes, Thank you... I got my answer. I used parameterized query...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900