|
-
Apr 8th, 2002, 11:23 AM
#1
Thread Starter
Fanatic Member
Trouble with strings in SQL Statement
I'm having a terrible time using strings in my SQL statement. If one of the fields contains a ' then I get an syntax error. I've tried several ways to try an fix this, this is the most recent. Any help with this is EXTREMELY appreciated as I have been stuck on this for 4 days now.
VB Code:
SQL = "INSERT into " & table & " VALUES ('" _
& Replace(strFilepath, "'", """") & "','" _
& Replace(strFileName, "'", """") & "','" _
& Replace(strFileSize, "'", """") & "','" _
& Replace(strArtist, "'", """") & "','" _
& Replace(strTitle, "'", """") & "','" _
& Replace(strAlbum, "'", """") & "','" _
& Replace(strFrequency, "'", """") & "','" _
& Replace(strBitrate, "'", """") & "','" _
& Replace(strLength, "'", """") & "','" _
& Replace(strTrack, "'", """") & "')"
Cnn.Execute (SQL)
-
Apr 8th, 2002, 11:55 AM
#2
Fanatic Member
I think you're replacing with the wrong characters. Try as in the following example.
Code:
Replace(strFilepath, "'", "''") etc...
The liver is bad. It must be punished.
-
Apr 8th, 2002, 11:59 AM
#3
Thread Starter
Fanatic Member
I've tried that,...
and I still get the same error.
-
Apr 8th, 2002, 12:03 PM
#4
Fanatic Member
I just noticed...
There's 2 things wrong with the SQL statement. Firstly, keep the Replace they way it is in my example.
The syntax eror you're getting is due to you not specifying the fields you want to insert to (just noticed that now. )
It should be of the form
Code:
INSERT INTO tblTableName(Column1,Column2...ColumnN)
VALUES(Value1,Value2...ValueN)
The liver is bad. It must be punished.
-
Apr 8th, 2002, 12:19 PM
#5
Thread Starter
Fanatic Member
What's wrong now...Syntax Error
Ok great! Now I'm getting a syntax error in my SQL statement. Also you don't need the column names unless your adding info to items that are not in order. Anyway, I'm getting a syntax error now. What's wrong with it now?
VB Code:
'Use SQL to insert the information in the strings into the table
SQL = "INSERT into " & table & "(FilePath, Filename, Filesize, Artist, Title, Album, Frequency, Bitrate, Length, Track)VALUES ('" _
& Replace(strFilepath, "'", "''") & "','" _
& Replace(strFileName, "'", "''") & "','" _
& Replace(strFileSize, "'", "''") & "','" _
& Replace(strArtist, "'", "''") & "','" _
& Replace(strTitle, "'", "''") & "','" _
& Replace(strAlbum, "'", "''") & "','" _
& Replace(strFrequency, "'", "''") & "','" _
& Replace(strBitrate, "'", "''") & "','" _
& Replace(strLength, "'", "''") & "','" _
& Replace(strTrack, "'", "''") & "')"
Cnn.Execute (SQL)
-
Apr 8th, 2002, 01:07 PM
#6
Fanatic Member
should be a space in between:
Track)VALUES
btw- I don't know if vb is forgiving on this (using function syntax when nothing is returned). If not, try no parentheses.
Cnn.Execute SQL
VB 6.0, Access, Sql server, Asp
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
|