Share via


How to pass the string along with the Double Quotes in c#?

Question

Thursday, September 6, 2007 12:56 PM

Hi,

      I am using VS 2003 and asp.net ,C#

          I have a requirement where in i have to pass a string with double quotes to the sqlparameter to execute a stored procedure.

the scenario is as follows

 string str =" "A" "so the sting should contain character A with Double quotes

i am using escape characters like this str = " \A\ ";  (\ is an escape character for " in c#)

but this works fine while printing but not for passing the string,,could any one plz help me out on this??

Thanks in advance

 

 

 

All replies (6)

Thursday, September 6, 2007 3:04 PM ✅Answered

 YOu can use string concatenation for that

string str =  "\"+"A"+"\";

StringBuffer strBuf = new StringBuffer();

strBuf.Append(str);

This will work for you

 

Regards

Muhammad Tabish Sarwar 


Thursday, September 6, 2007 3:09 PM ✅Answered

Hi try this out,
string str = @"""A""";
(The result is "A" ) I hope that's what you wanted?


Monday, September 10, 2007 2:17 AM ✅Answered

 SqlParameters.Add("@ParamName", SqlDbType.VarChar).Value = "\A\";  is a right way to assign parameters.

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparametercollection_members.aspx

Thanks


Tuesday, September 11, 2007 11:45 AM

 

 

In all the replies, i was asked to use escape character    ( \) ,

 but when i pass this string to Sqlparameter, its taking it as it is..i.e like \A\

this escape charater works fine for printing..but not for passing it to sqlparameter

Can any one suggest me the alternative,,,Thanks in Advance..

 


Tuesday, September 11, 2007 11:45 PM

Hi pradeep

You can also try single quote inside double quote marks.

Give tries and test it.

Thanks


Monday, May 13, 2013 6:00 PM

Hi try this out,
string str = @"""A""";
(The result is "A" ) I hope that's what you wanted?

Thanks for this ^ How about multiple values in a single line? 

"A", "B", "C", etc; Finding it tricky to find.