ecco la funzioncina per togliere caratteri "fastidiosi" dalla stringa sql:
codice:
Function ChkString(str)
ChkString = Replace(str, "'", "''")
ChkString = Replace(str, "|", "||")
End Function
ed ecco una stringa sql che richiama la funzione prendendo dati da un form:
codice:
StrSql = "insert into pippo (nome, cognome, note) Values ("
StrSql = StrSql & "'" & ChkString(Request.Form("nome")) & "', "
StrSql = StrSql & "'" & ChkString(Request.Form("cognome")) & "', "
StrSql = StrSql & "'" & ChkString(Request.Form("note")) & "')"
Se mando in esecuzione questa stringa sql con valori contenenti apici ottengo il classico errore:
...Syntax error (missing operator) in query expression...
Come mai gli apici non vengono sostituiti dalla funzione?
Ma sopratutto, perchè il carattere | viene correttamente sostituito da || mentre il carattere ' non viene cambato?