VB.net Escaping

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stefan Richter

    #1

    VB.net Escaping

    How do I encode double quotes and quotes and in a string in VB.NET?
    It also has to be save for MS SQL Server...


    Stefan


  • Dan Brussee

    #2
    Re: VB.net Escaping

    If you use stored procedures, you dont need a lot of the quote and
    other escaping you need to do otherwise. That being said, the only
    "quote" issue you have (no pun intended) is with single quotes. In
    this case, double the single quotes. A common way of doing this is
    with the Replace method ...

    sql = replace(str, "'", "''")

    That's a single quote surrounded by double quotes as the 2nd parameter
    and two single quotes surrounded by double quotes as the 3rd
    parameter.


    On Tue, 25 May 2004 02:56:08 +0200, "Stefan Richter"
    <spam@spammenot .com> wrote:
    [color=blue]
    >How do I encode double quotes and quotes and in a string in VB.NET?
    >It also has to be save for MS SQL Server...
    >
    >
    >Stefan
    >[/color]

    Comment

    • Stefan Richter

      #3
      Re: VB.net Escaping

      thx, works!


      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: VB.net Escaping

        Stefan Richter <spam@spammenot .com> wrote:[color=blue]
        > How do I encode double quotes and quotes and in a string in VB.NET?
        > It also has to be save for MS SQL Server...[/color]

        I would recommend avoiding escaping entirely when it comes to SQL
        statements - use parameters instead, and you don't need to worry about
        formatting or escaping.

        You don't have to be using stored procedures to use parameters.

        See http://www.pobox.com/~skeet/csharp/faq/#db.parameters for more
        information.

        --
        Jon Skeet - <skeet@pobox.co m>
        Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

        If replying to the group, please do not mail me too

        Comment

        • Mattias Sjögren

          #5
          Re: VB.net Escaping

          Stefan,
          [color=blue]
          >How do I encode double quotes and quotes and in a string in VB.NET?[/color]

          You include double quotes in a string by doubling them, like this

          "a ""quoted"" word"



          Mattias

          --
          Mattias Sjögren [MVP] mattias @ mvps.org
          http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
          Please reply only to the newsgroup.

          Comment

          Working...