Results 1 to 4 of 4

Thread: MySQL: and Quotation Marks **Resolved**

  1. #1

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Resolved MySQL: and Quotation Marks **Resolved**

    How would I use the following string to data from a MySQL Table:

    Mark's Computer

    I have tried the following and no luck:

    1) I have used the escape Character (Back Slash \) followed by a single
    quote (\') as documented in the MySQL Help File - No Good
    2) I also tried changing the entire string into Ascii - No Good
    3) I Used the MySQL escape character again '\' and typed the Ascii code
    after it - No Good

    VB Code:
    1. strSQL = "SELECT * FROM MyTable WHERE ComField ='[COLOR=Red]Mark's[/COLOR]'"

    Any Ideas?
    Last edited by Mark Gambo; May 30th, 2005 at 09:23 PM.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  2. #2

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: MySQL: and Quotation Marks

    I forgot to add that I am able to save (insert) the following string without a problem:

    Mark's Computer's Mouse

    But when I attempt to retrieve that record I get the following error message:
    Attached Images Attached Images  
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  3. #3
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: MySQL: and Quotation Marks

    VB Code:
    1. Crit="Mark's"
    2.  
    3. strSQL = "SELECT * FROM MyTable WHERE ComField ='" & CleanText(Crit) & "'"
    4. Public Function CleanText(strIn As String) As String
    5.     On Error GoTo VBError
    6.     Dim iAcnt As Long
    7.     Dim strString As String
    8.     Dim vLimit As Long
    9.     vLimit = Len(strIn)
    10.     For iAcnt = 1 To vLimit
    11.         Select Case Asc(Mid$(strIn, iAcnt, 1))
    12.         Case 10, 13
    13.             strString = strString & Mid$(strIn, iAcnt, 1)
    14.         Case 124
    15.             strString = strString & "!"
    16.         Case 39
    17.             strString = strString & "''"
    18.         Case 34
    19.             strString = strString & """"
    20.         Case Is < 32
    21.             strString = strString & " "
    22.         Case Is > 126
    23.             strString = strString & " "
    24.         Case Else
    25.             strString = strString & Mid$(strIn, iAcnt, 1)
    26.         End Select
    27.     Next
    28.     CleanText = strString
    29.     CleanText = Trim$(CleanText)
    30. Exit Function
    31. VBError:
    32.     MsgBox "VBError in Sub Parse_SQL_Text : " & Err.Number & " - " & Err.Description
    33.     Resume Next
    34. End Function
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  4. #4

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Resolved Re: MySQL: and Quotation Marks

    Quote Originally Posted by dee-u
    VB Code:
    1. Crit="Mark's"
    2.  
    3. strSQL = "SELECT * FROM MyTable WHERE ComField ='" & CleanText(Crit) & "'"
    4. Public Function CleanText(strIn As String) As String
    5.     On Error GoTo VBError
    6.     Dim iAcnt As Long
    7.     Dim strString As String
    8.     Dim vLimit As Long
    9.     vLimit = Len(strIn)
    10.     For iAcnt = 1 To vLimit
    11.         Select Case Asc(Mid$(strIn, iAcnt, 1))
    12.         Case 10, 13
    13.             strString = strString & Mid$(strIn, iAcnt, 1)
    14.         Case 124
    15.             strString = strString & "!"
    16.         Case 39
    17.             strString = strString & "''"
    18.         Case 34
    19.             strString = strString & """"
    20.         Case Is < 32
    21.             strString = strString & " "
    22.         Case Is > 126
    23.             strString = strString & " "
    24.         Case Else
    25.             strString = strString & Mid$(strIn, iAcnt, 1)
    26.         End Select
    27.     Next
    28.     CleanText = strString
    29.     CleanText = Trim$(CleanText)
    30. Exit Function
    31. VBError:
    32.     MsgBox "VBError in Sub Parse_SQL_Text : " & Err.Number & " - " & Err.Description
    33.     Resume Next
    34. End Function
    Thanks, you solved the problem!!!

    EDIT - What about ? / \ ` etc?
    Last edited by Mark Gambo; May 30th, 2005 at 09:22 PM.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


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