Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

the character

Hello!

I have this code line to insert a name file in the database:

conn.Execute "INSERT INTO FILES (nome_fil) VALUES ('" & nome_file & "');"

If the name file have the character ' it doesn’t save the string in the database! It doesn't give any error!
Why does this happen?!

Thanks :)
[349 byte] By [estrela666] at [2007-11-11 7:54:39]
# 1 Re: the character
Use the Replace command to replace the single quote (') with two single quotes (''). If you don't do this your SQL statement is invalid.
pclement at 2007-11-11 17:26:12 >
# 2 Re: the character
As you'll notice from your INSERT statement, SQL uses the ' character to delimit data for string/text fields. [look just before and after your variable nome_file]. If the data contains the ' character, there are several ways to get SQL to include it in your database data. The easiest one I know is:

conn.Execute "INSERT INTO FILES (nome_fil) VALUES ('" & Replace(nome_file, "'", "''") & "');"

The second red text is 2 single ' characters, not 1 " character.
doofusboy at 2007-11-11 17:27:13 >
# 3 Re: the character
thanks!
estrela666 at 2007-11-11 17:28:21 >