Double quotes issue

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Abdul Azeem

    #1

    Double quotes issue

    Hi All

    I have some data string like ~!@#$%'^&(*("}[;asd"> which contains double
    quote and greater then sign, first I need to insert this value into
    database, second this inserted value I have display in a textbox by
    retriving from database, as it has "> at end of the string values are
    getting discarded. if any of you have worked or know how to solve this issue
    pls help me.

    Thanks in Advance.
    - Azeem.



  • Jon Skeet [C# MVP]

    #2
    Re: Double quotes issue

    Abdul Azeem <abdulazeem@abc .com> wrote:[color=blue]
    > I have some data string like ~!@#$%'^&(*("}[;asd"> which contains double
    > quote and greater then sign, first I need to insert this value into
    > database, second this inserted value I have display in a textbox by
    > retriving from database, as it has "> at end of the string values are
    > getting discarded. if any of you have worked or know how to solve this issue
    > pls help me.[/color]

    Use a parameterised SQL statement rather than trying to insert the
    literal value into the SQL. This also has security benefits (no SQL
    injection attacks) and potential performance benefits depending on the
    database.

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

    • Abdul Azeem

      #3
      Re: Double quotes issue

      Thanks Jon, I will use parameterised SQL for inserting data into database
      but while display back into a TextBox the values are getting discarding,
      could you give me any solution for this pls.

      Thanks,
      - Azeem.


      "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
      news:MPG.1cfb85 b7e91dd8fd98c18 3@msnews.micros oft.com...[color=blue]
      > Abdul Azeem <abdulazeem@abc .com> wrote:[color=green]
      > > I have some data string like ~!@#$%'^&(*("}[;asd"> which contains[/color][/color]
      double[color=blue][color=green]
      > > quote and greater then sign, first I need to insert this value into
      > > database, second this inserted value I have display in a textbox by
      > > retriving from database, as it has "> at end of the string values are
      > > getting discarded. if any of you have worked or know how to solve this[/color][/color]
      issue[color=blue][color=green]
      > > pls help me.[/color]
      >
      > Use a parameterised SQL statement rather than trying to insert the
      > literal value into the SQL. This also has security benefits (no SQL
      > injection attacks) and potential performance benefits depending on the
      > database.
      >
      > --
      > Jon Skeet - <skeet@pobox.co m>
      > http://www.pobox.com/~skeet
      > If replying to the group, please do not mail me too[/color]


      Comment

      • Cor Ligthert

        #4
        Re: Double quotes issue

        Abdul,

        This shows for me 4 double quotes in a textbox (winforms)
        Dim a As String = """"""""""
        Dim b As String = a
        Me.TextBox1.Tex t = b

        I hope this helps,

        Cor


        Comment

        • Bob Barrows [MVP]

          #5
          Re: Double quotes issue

          Abdul Azeem wrote:[color=blue]
          > Hi All
          >
          > I have some data string like ~!@#$%'^&(*("}[;asd"> which contains
          > double quote and greater then sign, first I need to insert this value
          > into database, second this inserted value I have display in a textbox
          > by retriving from database, as it has "> at end of the string values
          > are getting discarded. if any of you have worked or know how to solve
          > this issue pls help me.
          >[/color]
          You've crossposted two newsgroups that cover different technologies. Since I
          am reading this in the .asp.general newsgroup, I will give a "classic" asp
          solution. If you actually need a .Net solution, let us know and remove the
          classic asp group from your crosspost.

          Solution:
          Use parameters to store the data into the database.
          Use server.htmlenco de when writing the data retrieved from the database to
          the Response. Example:

          <INPUT value="<%=serve r.htmlencode(da tafromdatabase) %>">

          Bob Barrows
          --
          Microsoft MVP - ASP/ASP.NET
          Please reply to the newsgroup. This email account is my spam trap so I
          don't check it very often. If you must reply off-line, then remove the
          "NO SPAM"


          Comment

          • Jay B. Harlow [MVP - Outlook]

            #6
            Re: Double quotes issue

            Abdul,
            Are you using ASP or ASP.NET? as you cross posted to both technologies.

            As Bob showed you can user server.htmlenco de in ASP to encode the string.

            In ASP.NET you can use HttpUtility.Htm lEncode to encode the string.

            http://msdn.microsoft.com/library/de...ncodeTopic.asp

            It appears HttpUtility.Htm lDecode has an example of calling the above
            method.

            Hope this helps
            Jay

            "Abdul Azeem" <abdulazeem@abc .com> wrote in message
            news:e7%23cY11X FHA.2996@TK2MSF TNGP10.phx.gbl. ..
            | Hi All
            |
            | I have some data string like ~!@#$%'^&(*("}[;asd"> which contains double
            | quote and greater then sign, first I need to insert this value into
            | database, second this inserted value I have display in a textbox by
            | retriving from database, as it has "> at end of the string values are
            | getting discarded. if any of you have worked or know how to solve this
            issue
            | pls help me.
            |
            | Thanks in Advance.
            | - Azeem.
            |
            |
            |


            Comment

            • Jon Skeet [C# MVP]

              #7
              Re: Double quotes issue

              Abdul Azeem <abdulazeem@abc .com> wrote:[color=blue]
              > Thanks Jon, I will use parameterised SQL for inserting data into database
              > but while display back into a TextBox the values are getting discarding,
              > could you give me any solution for this pls.[/color]

              They shouldn't be.

              Could you post a short but complete program which demonstrates the
              problem?

              See http://www.pobox.com/~skeet/csharp/complete.html for details of
              what I mean by that.

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

              • Abdul Azeem

                #8
                Re: Double quotes issue

                Hi Jay

                I am using ASP server.htmlenco de is not working I have given like <input
                type="text" value= server.htmlenco de("myEncodedTe xt") name="text1">,

                is this the correct way?

                Thanks,
                - Azeem.


                "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP @msn.com> wrote in message
                news:OMgjCx5XFH A.616@TK2MSFTNG P12.phx.gbl...[color=blue]
                > Abdul,
                > Are you using ASP or ASP.NET? as you cross posted to both technologies.
                >
                > As Bob showed you can user server.htmlenco de in ASP to encode the string.
                >
                > In ASP.NET you can use HttpUtility.Htm lEncode to encode the string.
                >
                >[/color]
                http://msdn.microsoft.com/library/de...us/cpref/html/
                frlrfSystemWebH ttpUtilityClass HtmlEncodeTopic .asp[color=blue]
                >
                > It appears HttpUtility.Htm lDecode has an example of calling the above
                > method.
                >
                > Hope this helps
                > Jay
                >
                > "Abdul Azeem" <abdulazeem@abc .com> wrote in message
                > news:e7%23cY11X FHA.2996@TK2MSF TNGP10.phx.gbl. ..
                > | Hi All
                > |
                > | I have some data string like ~!@#$%'^&(*("}[;asd"> which contains[/color]
                double[color=blue]
                > | quote and greater then sign, first I need to insert this value into
                > | database, second this inserted value I have display in a textbox by
                > | retriving from database, as it has "> at end of the string values are
                > | getting discarded. if any of you have worked or know how to solve this
                > issue
                > | pls help me.
                > |
                > | Thanks in Advance.
                > | - Azeem.
                > |
                > |
                > |
                >
                >[/color]


                Comment

                • Bob Barrows [MVP]

                  #9
                  Re: Double quotes issue

                  Abdul Azeem wrote:[color=blue]
                  > Hi Jay
                  >
                  > I am using ASP server.htmlenco de is not working I have given like
                  > <input type="text" value= server.htmlenco de("myEncodedTe xt")
                  > name="text1">,
                  >
                  > is this the correct way?
                  >[/color]

                  No.

                  It's _server_.htmlen code. In other words, it's a _server-side_ function. It
                  can only be executed in a server-side script block as I showed in my first
                  reply to you.Also, the attribute value should be delimited with quotes:

                  <input
                  type="text" value= "
                  <%=server.htmle ncode("myEncode dText")%>
                  " name="text1">

                  <%= is shorthand for
                  <% Response.Write

                  Bob Barrows
                  --
                  Microsoft MVP - ASP/ASP.NET
                  Please reply to the newsgroup. This email account is my spam trap so I
                  don't check it very often. If you must reply off-line, then remove the
                  "NO SPAM"


                  Comment

                  • Brian Cryer

                    #10
                    Re: Double quotes issue

                    You may find that values don't appear when you view them on an HTML page
                    because the text you are trying to display contains characters which the
                    browser is treating as HTML (i.e. a sort of HTML-injection-attack rather
                    than a SQL-injection attack.)

                    If you run it through the IDE do you see the correct value in the debugger?

                    Brian.

                    Brian Cryer's home page, a collection of notes on my professional and personal interests. Including C#, VB.Net, Windows, DB admin, Delphi and more.


                    "Abdul Azeem" <abdulazeem@abc .com> wrote in message
                    news:%239mlwZ2X FHA.3540@TK2MSF TNGP15.phx.gbl. ..[color=blue]
                    > Thanks Jon, I will use parameterised SQL for inserting data into database
                    > but while display back into a TextBox the values are getting discarding,
                    > could you give me any solution for this pls.
                    >
                    > Thanks,
                    > - Azeem.
                    >
                    >
                    > "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
                    > news:MPG.1cfb85 b7e91dd8fd98c18 3@msnews.micros oft.com...[color=green]
                    >> Abdul Azeem <abdulazeem@abc .com> wrote:[color=darkred]
                    >> > I have some data string like ~!@#$%'^&(*("}[;asd"> which contains[/color][/color]
                    > double[color=green][color=darkred]
                    >> > quote and greater then sign, first I need to insert this value into
                    >> > database, second this inserted value I have display in a textbox by
                    >> > retriving from database, as it has "> at end of the string values are
                    >> > getting discarded. if any of you have worked or know how to solve this[/color][/color]
                    > issue[color=green][color=darkred]
                    >> > pls help me.[/color]
                    >>
                    >> Use a parameterised SQL statement rather than trying to insert the
                    >> literal value into the SQL. This also has security benefits (no SQL
                    >> injection attacks) and potential performance benefits depending on the
                    >> database.
                    >>
                    >> --
                    >> Jon Skeet - <skeet@pobox.co m>
                    >> http://www.pobox.com/~skeet
                    >> If replying to the group, please do not mail me too[/color]
                    >
                    >[/color]


                    Comment

                    Working...