Results 1 to 2 of 2

Thread: SQL Update on data with an apostrophe in it

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2001
    Posts
    3

    SQL Update on data with an apostrophe in it

    I am trying to update an existing database record. The value I am trying to put in the [Title] field of the database has an apostrophe in it. I cannot get the syntax of my SQL update query coded right so the value updates the way it should.

    This is the SQL

    strSQL = "UPDATE Video " & _
    "SET [Title] = '" & txtTitle.Text & "', " & _
    "[Category] = '" & cboCategory.Text & "', " & _
    "[Studio ID] = '" & cboStudioID.Text & "', " & _
    "[Length] = " & intlength & _
    " WHERE [Movie Number] = '" & mskMovieNumber.Text & "'"

    For example when txtTitle.Text is equal to My Mother's Diary, I get a syntax error.

    I tried to change the SQL for the title part to:
    "SET [Title] = "" & txtTitle.Text & "", " & _
    which updated the Title on my record to & txtTitle.Text &

    I also tried this:
    "SET [Title] = ''" & txtTitle.Text & "'', " & _
    which gave my another syntax error.

    I am using VB 6.0 and a Microsoft Access 97 database file.

    Any help you can give me would be most appreciated!

    Deb

  2. #2
    Hyperactive Member PJB's Avatar
    Join Date
    Aug 2000
    Location
    dunno at the moment
    Posts
    302

    Deb

    here's a function i've used in .ASP files before but have never tried it in VB:

    Code:
    Replace(txtTitle.Text, "'", "''")
    I usually set a variable = to the above statement then put the variable in my SQL statement(don't know if that makes any difference), if that doesn't work look for something along those lines, i don't think the answer is changing the SQL statement.
    VB6.0 SP4
    Windows 2000
    I'm thinking of a number between

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