Click to See Complete Forum and Search --> : Help with string "\"
Darckang3l
Jun 27th, 2007, 03:11 PM
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
ComputerJy
Jun 27th, 2007, 03:15 PM
Either:
string sConnection= @"server=NB60\SQLEXPRESS;database=x;uid=a;pwd=;"
Or:
string sConnection= "server=NB60\\SQLEXPRESS;database=x;uid=a;pwd=;"
effekt26
Jun 27th, 2007, 06:17 PM
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...
eranga262154
Jun 27th, 2007, 10:34 PM
escape the escape character
Easy way is that use @ sign, is it?
phrajib
Jun 28th, 2007, 03:58 AM
I am clear about the problem.
For any special character like \ or ' you have to use an additional \ in c#
like \\ or \'
-Rajib
JenniferBabe
Jun 28th, 2007, 08:57 AM
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.
eranga262154
Jul 1st, 2007, 09:56 PM
Traditionally/normally I used @ sign. Actually it use lots of people. So easy to understand.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.