Results 1 to 5 of 5

Thread: Not able to update record

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2000
    Location
    Singapore
    Posts
    59

    Exclamation

    Hi all,
    I am not able to update a record with the following type.
    Front end VB6.
    Database access.

    Table about company.
    fields. id(number), companyname(text),status(text)

    If I update a record without "'" symbol in the company name field everything works fine.

    But if I give the company name like " ONG'S " in the update state ment it strucks. It is giving some syntax error in the SQL statement.

    Anyone please help me how to over come with this "'" symbol to include in a company name.

    Thanks in advance
    karun
    With regards,
    Karun

  2. #2
    Addicted Member
    Join Date
    Feb 1999
    Location
    Belfast
    Posts
    254

    Can't Update

    Hello,
    I am presuming the issue is with the VB string. In which case try this ( insert example ):

    ls_SQL = "Insert into customer(name) values(""gerry's"")"

    Thanks

    lenin

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2000
    Location
    Singapore
    Posts
    59

    Red face

    Hai,
    If it is hard coded it is working.It is already I tried.
    But I cannot pass it through a variable.

    Can You and any please help me

    Thanks
    karun
    With regards,
    Karun

  4. #4
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    This might help you:

    Code:
    Option Explicit
    Dim db As Database
    Const Quote = """"
    
    
    
    Private Sub Command2_Click()
    Dim strSQL As String
    'this works
    strSQL = "INSERT into table1(colour1)VALUES(" & Quote & Text1.Text & Quote & ");"
    
    'this fails with ONG'S
    'strSQL = "INSERT into table1(colour1)VALUES('" & Text1.Text & "');"
    
    db.Execute strSQL
    
    End Sub
    Mark
    -------------------

  5. #5
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844
    Or you could just use VB6's replace function on all sql statements before you execute them:

    Code:
    strSQL = "Select * from Customers where LastName = 'O'Brian'"
    
    'note that the 3rd parameter is 2 single quotes
    'while the 2nd parameter is 1 single quote
    strSQL = replace(strSQL, "'", "''")
    
    'the sql is now properly formatted to allow
    'querying on single quotes
    set rs = cn.execute(strSQL)

    Tom

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