adding strings with a quote in SQL

Discussion in 'ASP .Net' started by Thierry, Jan 22, 2004.

  1. Thierry

    Thierry Guest

    Hi,



    I've got a problem with adding strings with a quote in SQL.



    Dim LocationName As String = "for' example"



    Dim strQuery As String = "select count(*) as fldNumber "

    strQuery += "from " & TableName & " "

    strQuery += "where " & FieldName & " like ' " & LocationName & "% '
    "



    What do I have to do to get LocationName into the query and get this
    working?



    Thanks,

    Thierry
     
    Thierry, Jan 22, 2004
    #1
    1. Advertisements

  2. Thierry

    gabriel Guest

    You have to "escape" the quote. How you do that depends on the database.
    Which database are you using?
     
    gabriel, Jan 22, 2004
    #2
    1. Advertisements

  3. Thierry

    Thierry Guest

    I use SQL-server.
    How can I escape the quote.


     
    Thierry, Jan 23, 2004
    #3
  4. Thierry

    bj daniels Guest

    I may be misunderstanding you question - but I run a function that replaces
    ' with '' (one apostrophie with 2 apostrophies) and I have not had problems
    since. I use SQL server also.

    bj daniels
     
    bj daniels, Jan 23, 2004
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.