Results 1 to 7 of 7

Thread: Help with string "\"

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    20

    Help with string "\"

    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

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Help with string "\"

    Either:
    Code:
    string sConnection= @"server=NB60\SQLEXPRESS;database=x;uid=a;pwd=;"
    Or:
    Code:
    string sConnection= "server=NB60\\SQLEXPRESS;database=x;uid=a;pwd=;"
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3
    Addicted Member effekt26's Avatar
    Join Date
    Nov 2006
    Posts
    138

    Re: Help with string "\"

    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...

  4. #4
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: Help with string "\"

    Quote Originally Posted by effekt26
    escape the escape character
    Easy way is that use @ sign, is it?
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

  5. #5
    Lively Member
    Join Date
    Mar 2005
    Location
    Dhaka, Bangladesh
    Posts
    102

    Re: Help with string "\"

    I am clear about the problem.

    For any special character like \ or ' you have to use an additional \ in c#
    like \\ or \'

    -Rajib
    Please Rate every reply if it is useful to u

  6. #6
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: Help with string "\"

    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.

  7. #7
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: Help with string "\"

    Traditionally/normally I used @ sign. Actually it use lots of people. So easy to understand.
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width