Ask a Question related to ASP, Design and Development.

  1. #1

    Default sql UPDATE fails

    Hi,

    I've got a page which updates a record, but it fails if the text used
    contains an apostrophe. I understand I need to replace apostrophes
    with double quotes in order for it to work?

    I also know there's a piece of code which can be used to do this, and
    replace all apostrophes so that it works.

    Any help would be greatly appreciated!

    Cheers,
    Joseph
    Joseph Guest

  2. Similar Questions and Discussions

    1. Update fails behind a MS ISA proxy server
      We have all our clients behind a MS ISA proxy server. When Flash player tries to update itself, or when you try to install it from the download...
    2. Update fails on CF 7.0, works on CF 5.0
      I'm not sure what's going on. The UPDATE below works with CF5.0 with MS Access ODBC, but fails with CF 7.0 with MS Access with Unicode. I first...
    3. 7.0.1 Update fails
      I have tried updating to 7.0.1 from 7.0 but the install is not there! When I start the servers and login to CF Admin I am only opening version 7.0...
    4. Web Service fails after update
      I have a situation in which I have a .cfm page on my server which invokes a CF web service on the same server. Everything is fine except that when I...
    5. Acorbat 6.01 Update Fails to Install
      Some of us have better things to do than un-install/re-install. You would think the install would go to a browse window instead of just bailing....
  3. #2

    Default Re: sql UPDATE fails

    Joseph wrote:
    > Hi,
    >
    > I've got a page which updates a record, but it fails if the text used
    > contains an apostrophe. I understand I need to replace apostrophes
    > with double quotes in order for it to work?
    No. you need to replace the apostrophes with two apostrophes. A double quote
    is a single character: ". This is not what you need to do.
    >
    > I also know there's a piece of code which can be used to do this, and
    > replace all apostrophes so that it works.
    >
    Dim sText
    sText = request("data")
    'data contains "O'Conner's Place"
    sText = Replace(sText,"'","''")

    This replaces each apostrophe with two apostrophes.

    HTH,
    Bob Barrows


    Bob Barrows Guest

  4. #3

    Default Re: sql UPDATE fails

    Hi Bob,

    Thanks for that. Where exactly should that code go, I've placed it
    before mu update code, ie:

    Dim sText
    sText = request("ReportGuideDescription")
    sText = Replace(sText,"'","''")

    Set conn = Server.CreateObject ("ADODB.Connection")
    conn.ConnectionTimeout = Application("DevReportMaint_ConnectionTimeout")
    conn.CommandTimeout = Application("DevReportMaint_CommandTimeout")
    conn.Open "DevReportMaint", "DevReportMaintUser", "Spike1"

    conn.Execute "UPDATE tblReport SET" & _
    " ReportName = '"& request("ReportName") &"', " & _
    " ReportCatName = '"& request("ReportCatName") &"', SelectionCriteria =
    '"& request("SelectionCriteria")& "', " & _
    " ReportGuideDescription = '"& request("ReportGuideDescription")& "',
    " & _
    " FullReportDescription = '"& request("FullReportDescription")& "', " &
    _
    " VersionCreatedFor = '"& request("VersionCreatedFor")& "', " & _
    " ClientCreatedFor = '"& request("ClientCreatedFor") &"', ReleasedTo =
    '"& request("ReleasedTo") &"', " &_
    " TidyUpDescription = '"& request("TidyUpDescription") &"', MultiPage =
    '"& request("MultiPage") &"', " & _
    " HeadingCellsShowBorders = '"& request("HeadingCellsShowBorders") &"',
    " & _
    " Chart = '"& request("Chart") &"', Landscape = '"&
    request("Landscape") &"', " & _
    " ReleasedToOthers = '"& request("ReleasedToOthers") &"' " & _
    " WHERE ReportId = '"& request("ReportId") &"'"

    conn.Close
    set conn = Nothing


    Also, I replaced "data" in the line 'sText = request("data")' with the
    name of the field I wanted to replace the text in.

    However it still doesn't work!!


    Thanks,
    Joseph

    Phil Jagielka- the best young footballer in Britain, no question!!

    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    MillHillBlade Guest

  5. #4

    Default Re: sql UPDATE fails

    MillHillBlade wrote:
    > Hi Bob,
    >
    > Thanks for that. Where exactly should that code go, I've placed it
    > before mu update code, ie:
    >
    > Dim sText
    > sText = request("ReportGuideDescription")
    This should be the name of the variable, not the name of the field, unless
    it's the same.
    > sText = Replace(sText,"'","''")
    >
    <irrelevant>
    > conn.Execute "UPDATE tblReport SET" & _
    > " ReportName = '"& request("ReportName") &"', " & _
    > " ReportCatName = '"& request("ReportCatName") &"', SelectionCriteria
    > = '"& request("SelectionCriteria")& "', " & _
    > " ReportGuideDescription = '"& request("ReportGuideDescription")& "',
    Why wouldn't you use sText here instead of
    request("ReportGuideDescription")? It seems fairly obvious doesn't it?
    You've gone to the trouble of creating the sText variable up above, and then
    you don't use it? Just in case you're missing my point:
    " ReportGuideDescription = '"& sText & "', " & _





    Bob Barrows Guest

  6. #5

    Default Re: sql UPDATE fails

    You set sText to be your safened value from your form (or querystring?) but
    then don't use it. Try this:



    Sub SafenSQL(ByRef sText)
    sText = Replace(sText, "'", "''")
    End Sub

    Dim sSQL
    Dim sReportName, sReportCatName, sSelectionCriteria,
    sReportGuideDescription, sFullReportDescription, sVersionCreatedFor,
    sClientCreatedFor, sReleasedTo, sTidyUpDescription, sMultiPage,
    sHeadingCellsShowBorders, sChart, sLandscape, sReleasedToOthers, sReportID
    '''It appears that you aren't using any integers, bits, or any other
    non-text data type. Hmm.

    sReportName = Request("ReportName")
    sReportCatName = Request("ReportCatName")
    sSelectionCriteria = Request("SelectionCriteria")
    '''etc. etc.

    SafenSQL sReportName
    SafenSQL sReportCatName
    SafeSQL sSelectionCriteria
    '''etc. etc.



    sSQL = "UPDATE tblReport SET ReportName = '" & sReportName &
    "',ReportCatName = '" & sReportCatName & "',SelectionCriteria='" &
    sSelectionCriteria & _
    "',ReportGuideDescription = '" & sReportGuideDescription &
    "',FullReportDescription = '" sFullReportDescription & "',VersionCreatedFor
    = '" & _
    sVersionCreatedFor & "',ClientCreatedFor = '" sClientCreatedFor &
    "',ReleasedTo ='" sReleasedTo & "', TidyUpDescription = '" &
    sTidyUpDescription & _ "', MultiPage ='" & sMultiPage &
    "',HeadingCellsShowBorders = '" & sHeadingCellsShowBorders & "',Chart = '"
    sChart & "', Landscape = '" & _
    sLandscape & "',ReleasedToOthers = '" & sReleasedToOthers & "' WHERE
    ReportId = '" & sReportId & "'"






    Set conn = Server.CreateObject ("ADODB.Connection")
    conn.ConnectionTimeout = Application("DevReportMaint_ConnectionTimeout")
    conn.CommandTimeout = Application("DevReportMaint_CommandTimeout")
    conn.Open "DevReportMaint", "DevReportMaintUser", "Spike1"
    conn.Execute sSQL
    conn.Close
    set conn = Nothing

    Ray at work





    "MillHillBlade" <anonymous@devdex.com> wrote in message
    news:OpImxRwPDHA.1216@TK2MSFTNGP11.phx.gbl...
    > Hi Bob,
    >
    > Thanks for that. Where exactly should that code go, I've placed it
    > before mu update code, ie:
    >
    > Dim sText
    > sText = request("ReportGuideDescription")
    > sText = Replace(sText,"'","''")
    >
    > Set conn = Server.CreateObject ("ADODB.Connection")
    > conn.ConnectionTimeout = Application("DevReportMaint_ConnectionTimeout")
    > conn.CommandTimeout = Application("DevReportMaint_CommandTimeout")
    > conn.Open "DevReportMaint", "DevReportMaintUser", "Spike1"
    >
    > conn.Execute "UPDATE tblReport SET" & _
    > " ReportName = '"& request("ReportName") &"', " & _
    > " ReportCatName = '"& request("ReportCatName") &"', SelectionCriteria =
    > '"& request("SelectionCriteria")& "', " & _
    > " ReportGuideDescription = '"& request("ReportGuideDescription")& "',
    > " & _
    > " FullReportDescription = '"& request("FullReportDescription")& "', " &
    > _
    > " VersionCreatedFor = '"& request("VersionCreatedFor")& "', " & _
    > " ClientCreatedFor = '"& request("ClientCreatedFor") &"', ReleasedTo =
    > '"& request("ReleasedTo") &"', " &_
    > " TidyUpDescription = '"& request("TidyUpDescription") &"', MultiPage =
    > '"& request("MultiPage") &"', " & _
    > " HeadingCellsShowBorders = '"& request("HeadingCellsShowBorders") &"',
    > " & _
    > " Chart = '"& request("Chart") &"', Landscape = '"&
    > request("Landscape") &"', " & _
    > " ReleasedToOthers = '"& request("ReleasedToOthers") &"' " & _
    > " WHERE ReportId = '"& request("ReportId") &"'"
    >
    > conn.Close
    > set conn = Nothing
    >
    >
    > Also, I replaced "data" in the line 'sText = request("data")' with the
    > name of the field I wanted to replace the text in.
    >
    > However it still doesn't work!!
    >
    >
    > Thanks,
    > Joseph
    >
    > Phil Jagielka- the best young footballer in Britain, no question!!
    >
    > *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    > Don't just participate in USENET...get rewarded for it!

    Ray at Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139