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)
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)