Hy all
I have a conection string with SQL : string sConnection= "server=NB60\SQLEXPRESS;database=x;uid=a;pwd=;"
the problem is with the "\" from the name of the server name
can sombody tell me how i can write the string "\" to be corectly
Printable View
Hy all
I have a conection string with SQL : string sConnection= "server=NB60\SQLEXPRESS;database=x;uid=a;pwd=;"
the problem is with the "\" from the name of the server name
can sombody tell me how i can write the string "\" to be corectly
Either:
Or:Code:string sConnection= @"server=NB60\SQLEXPRESS;database=x;uid=a;pwd=;"
Code:string sConnection= "server=NB60\\SQLEXPRESS;database=x;uid=a;pwd=;"
What is happening is C# is reading the '\' as an Escape Character. What you need to do, is, escape the escape character, to allow the string to be read properly...
Easy way is that use @ sign, is it?Quote:
Originally Posted by effekt26
I am clear about the problem.
For any special character like \ or ' you have to use an additional \ in c#
like \\ or \'
-Rajib
You could use the additional \ e.g. \\ or \' etc. But I think using the @ is a lot better, less typing and easier to understand for complex statements.
Traditionally/normally I used @ sign. Actually it use lots of people. So easy to understand.