|
-
May 14th, 2004, 01:51 AM
#1
Thread Starter
Junior Member
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
C ocuments and SettingswendysiaDesktoplogo.jpg
Is there any problem with my Insert query?
VB Code:
insertPhoto = "UPDATE employee SET photo = '" & Picpth & "' WHERE Emp_ID ='" & ID & "'"
-
May 14th, 2004, 02:07 AM
#2
Have you tried using Chr(47) instead of / ?
-
May 14th, 2004, 02:29 AM
#3
Thread Starter
Junior Member
How should I use the Chr(47)??
The update query is
VB Code:
insertPhoto = "UPDATE employee SET photo = '" + CommonDialog1.FileName + "' WHERE Emp_ID ='" & ID & "'"
The "/" character is in the string of CommonDialog1.FileName
-
May 14th, 2004, 02:37 AM
#4
Retired VBF Adm1nistrator
Try this :
VB Code:
Dim strPath As String: strPath = CommonDialog1.FileName
Dim strSQLStatement As String
If Not strPath = vbNullString Then
strPath = Replace(strPath, "\", "\b")
strSQLStatement = "UPDATE employee SET photo = '" & strPath & "' WHERE Emp_ID ='" & ID & "'"
End If
You need to use an escaped character to use a backslash.
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
May 14th, 2004, 02:37 AM
#5
Member
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:
Public Function pc_ValidationStr(pi_strValue As Variant) As String
Dim StrValidation As String
Dim strValues As String
Dim lngCnt As Long
Dim lngStrLong As Long
On Error GoTo errH
StrValidation = ""
If TypeName(pi_strValue) = "String" Then
strValues = Trim(pi_strValue)
lngStrLong = Len(strValues)
If lngStrLong > 0 Then
For lngCnt = 1 To lngStrLong
If Mid(strValues, lngCnt, 1) = "'" Then
If Not Right(StrValidation, 1) = "'" Then
StrValidation = StrValidation & Mid(strValues, lngCnt, 1) & "'"
End If
Else
StrValidation = StrValidation & Mid(strValues, lngCnt, 1)
End If
Next
End If
End If
pc_ValidationStr = StrValidation
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.
-
May 14th, 2004, 03:41 AM
#6
Thread Starter
Junior Member
-
May 14th, 2004, 03:47 AM
#7
Retired VBF Adm1nistrator
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
May 14th, 2004, 10:04 AM
#8
Show the code(s) you tried
-
May 14th, 2004, 10:51 AM
#9
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"
-
May 14th, 2004, 11:28 AM
#10
Fanatic Member
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
-
May 17th, 2004, 07:05 PM
#11
Thread Starter
Junior Member
This works for me

VB Code:
"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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|