Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - SQL Statement Help - Invalid chars

Reply
 
Old 09-17-2008   #1 (permalink)
Bob Smith


 
 

SQL Statement Help - Invalid chars

Does anyone have a VBScript function that will help escape common SQL
Characters.

An example would be something like inserting this SQL command with this string

string = "smith, jacob's"
SQL = "INSERT INTO MyTable (DisplayName) Values ('" & String & "')"
conn.Execute(SQL)

This would return an error. Other common charactors may include include \ '
% OR and other items. There may also be multiple entries of one or more of
these chars in the same string. any help would be appriciated. The source of
data is unpredictable.

Thanks


My System SpecsSystem Spec
Old 09-17-2008   #2 (permalink)
Bob Barrows [MVP]


 
 

Re: SQL Statement Help - Invalid chars

Bob Smith wrote:
Quote:

> Does anyone have a VBScript function that will help escape common SQL
> Characters.
>
> An example would be something like inserting this SQL command with
> this string
>
> string = "smith, jacob's"
> SQL = "INSERT INTO MyTable (DisplayName) Values ('" & String & "')"
> conn.Execute(SQL)
>
> This would return an error. Other common charactors may include
> include \ ' % OR and other items. There may also be multiple entries
> of one or more of these chars in the same string. any help would be
> appriciated. The source of data is unpredictable.
Use parameters instead of dynamic sql - the need for escaping characters
disappears ... along with the need to worry about delimiting data
values. Like this:

SQL = "INSERT INTO MyTable (DisplayName) Values (?)"
set cmd=createobject("adodb.command")
arparms=array("smith, jacob's")
set cmd=createobject("adodb.command")
cmd.commandtext=SQL
Set cmd.activeconnection=conn
cmd.execute ,arparms,129
'129=adCmdText + adExecuteNoRecords



--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
split string every tot chars PowerShell
Unicode chars munged? PowerShell
Telneting from Windows Vista hungs after typens some chars Vista networking & sharing
Format a string with non printable chars PowerShell
RE: Format a string with non printable chars PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46