Results 1 to 11 of 11

Thread: INSERT QUERY help!!!

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Posts
    22

    Unhappy INSERT QUERY help!!!

    I would like to insert these strings:
    C:/Documents and Settings/wendysia/Desktop/logo.jpg

    into my database(mysql) with the field type of VarChar(80)

    However, when the insert is done. I found out that the "/" character has been eliminated into
    Cocuments and SettingswendysiaDesktoplogo.jpg


    Is there any problem with my Insert query?
    VB Code:
    1. insertPhoto = "UPDATE employee SET photo = '" & Picpth & "' WHERE Emp_ID ='" & ID & "'"

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Have you tried using Chr(47) instead of / ?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Posts
    22
    How should I use the Chr(47)??

    The update query is
    VB Code:
    1. insertPhoto = "UPDATE employee SET photo = '" + CommonDialog1.FileName  + "' WHERE Emp_ID ='" & ID & "'"

    The "/" character is in the string of CommonDialog1.FileName

  4. #4
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Try this :

    VB Code:
    1. Dim strPath As String: strPath = CommonDialog1.FileName
    2. Dim strSQLStatement As String
    3. If Not strPath = vbNullString Then
    4.     strPath = Replace(strPath, "\", "\b")
    5.     strSQLStatement = "UPDATE employee SET photo = '" & strPath & "' WHERE Emp_ID ='" & ID & "'"
    6. End If

    You need to use an escaped character to use a backslash.
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  5. #5
    Member sahbasita's Avatar
    Join Date
    Feb 2004
    Location
    Loading ...
    Posts
    57

    Try this one !!

    Hi, Wendy ...

    Try this one. It takes a little bit code on your project. First you must create a validation function in a module. This is the sample :

    VB Code:
    1. Public Function pc_ValidationStr(pi_strValue As Variant) As String
    2. Dim StrValidation As String
    3. Dim strValues As String
    4. Dim lngCnt As Long
    5. Dim lngStrLong As Long
    6. On Error GoTo errH
    7. StrValidation = ""
    8.     If TypeName(pi_strValue) = "String" Then
    9.         strValues = Trim(pi_strValue)
    10.         lngStrLong = Len(strValues)
    11.         If lngStrLong > 0 Then
    12.             For lngCnt = 1 To lngStrLong
    13.                 If Mid(strValues, lngCnt, 1) = "'" Then
    14.                     If Not Right(StrValidation, 1) = "'" Then
    15.                         StrValidation = StrValidation & Mid(strValues, lngCnt, 1) & "'"
    16.                     End If
    17.                 Else
    18.                     StrValidation = StrValidation & Mid(strValues, lngCnt, 1)
    19.                 End If
    20.             Next
    21.         End If
    22.     End If
    23. pc_ValidationStr = StrValidation
    24. End Function

    After this one you can directly call the function in the query.
    i.e :
    insertPhoto = "UPDATE employee SET photo = " & pc_ValidationStr(picpth) & " WHERE ......"

    Hope it solve your problem.
    BlueE@gles

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Posts
    22
    It does not work......

    Do you guys have any other option?

  7. #7
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Did you try mine?
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Originally posted by wendymelon
    It does not work......

    Do you guys have any other option?
    Show the code(s) you tried

  9. #9
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    you do realize that your slashes are backwards??

    C:/Documents and Settings/wendysia/Desktop/logo.jpg

    should be

    C:\Documents and Settings\wendysia\Desktop\logo.jpg

    but...I believe that has to do with Unix? maybe? is your sql server running on unix?

    anyway...

    try replacing the \ with a : or a ^ then replace back when you read it back in

    picPath = Replace(picPath,"\","^")

    then reverse on read

    picPath = Replace(picPath,"^","\")
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  10. #10
    Fanatic Member ahara's Avatar
    Join Date
    Nov 2003
    Location
    Toronto
    Posts
    531
    if it is a backslash instead of the forward slashes shown in your example, the escape character is \ single backsash....so you would do \\ for each slash

    http://dev.mysql.com/doc/mysql/en/String_syntax.html

    It looks like there is no escape character for the forward slash, in which case you would want to swap it out as previously suggested in this thread.
    "Knowledge is gained when different people look at the same information in different ways"

    - Louis Pasteur

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Posts
    22
    This works for me


    VB Code:
    1. "UPDATE employee SET photo = 'C:/\Photo/\" & CommonDialog1.FileTitle & "' WHERE Emp_ID ='" & Id & "'"

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