Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2005
    Posts
    5

    Exclamation Unanswered: Apostrophe Special Character Trapping: Anybody who might helped me please

    elow first & foremost i would like to thank the people who helped me out in my dilemna before about mysql, THANK YOU THANK YOU VERY MUCH....
    For now in out thesis work we are already in the testing stage, our project which is due this february to our client a hotel, during one of our test we discovered that there is a SPECIAL CHARACTER THAT CAN'T BE TRAPT & this is the APOSTROPHE, our front end VB6 back end MySQL, what ever we do we can't trapt this error we even tried doing it like WINDOWS does it wherein an instance is renaming a filename that contains special characters & doing this an error comes out 'A Filename cannot contain the following special characters', for ours if im not mistaken its 'Error 40002' for the apostrophe.Could anybody out there help me cause im at a loss already so is the group...tnx & hoping for a reply for those people who have encountered this & fixed it, more power good day

  2. #2
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    one option is to write a function to replace instances of single apostrophes in strings with double apostrophes.

    IN other words. My last name is O'Quin.

    In order to insert O'Quin into a SQL database, I need to change it to O''Quin

    Code:
    strLastName = "O'Quin"
    strLastName = Replace(strLastName, "'", "''")
    Now you can use the string that's contained in strLastName in SQL statements from VB.
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


  3. #3
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    Your preferred approach, however, would be to use paramaterized queries with the ADO command object.

    Something along these lines (untested):
    Code:
    dim objC as ADODB.command
    dim objP as adodb.parameter
    dim rs as adodb.Recordset
    
    set objC  = new adodb.command
    set c.activeconnection = cn     ' cn previously instanciated & opened
    objC.CommandText = "Select Count(*) from tblCustomers Where LastName = ?"
    objC.CommandType = adCmdText
    
    set objP = objC.CreateParameter("LastName", adChar, adParamInput)
    objC.Parameters.Append objP
    
    objC.Parameters("LastName").Value = "O'Quin"
    
    db.Errors.Clear
    set rs = objC.Execute
    
    if db.Errors.Count > 0 then
      Msgbox "Errors Occurred - see db.Errors Collection"
    Else
      msgbox cStr(rs.Fields(0).Value) & " Records match the search criteria"
    Endif
    Last edited by loquin; 01-19-06 at 00:26.
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


  4. #4
    Join Date
    Nov 2005
    Posts
    5

    Talking tnx a bunch

    tnx a bunch, gonna try it all out

Posting Permissions

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