Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 13th, 2008, 04:03 PM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 205
Thanks: 4
Thanked 0 Times in 0 Posts
Default Insert renders error

Trying to insert a record using variables from a data set. Get error on variable myRow.Item(63).


insert into rjadevlib.f5514ar (f1, f2, f3) " values(" & "'" myRow.Item(63) & "'" & "," & "'" & myRow.Item(64) & "'" & "," & "'" & myRow.Item(65) & "'" & ")"


The content is:

insert into rjadevlib.f5514ar(f1, f2, f3) values('101 Sansbury's Way ','West Palm Beach ','Fl')


SQL0104: Token S was not valid. Valid tokens: ) ,.
Cause . . . . . : A syntax error was detected at token S. Token S is not a valid token.

Is there a way around this? I would like to test the variable "myRow.Item(63)" beforehand

 
Old October 13th, 2008, 05:42 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

You need to escape the ' in Sansbury's.

So you would need to execute the insert the as:
insert into rjadevlib.f5514ar(f1, f2, f3) values('101 Sansbury''s Way ','West Palm Beach ','Fl')

hth.


================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old October 13th, 2008, 09:28 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Since you are using VB, it's easy to do the escaping DParsons noted:
Code:
... = "insert into rjadevlib.f5514ar (f1, f2, f3) " _
    & " values('" Replace(myRow.Item(63),"'","''") & "'," _
    & "'" & Replace(myRow.Item(64),"'","''") & "'," _
    & "'" & Replace(myRow.Item(65),"'","''") & "')"
But can't you come up with better names for your DB fields than f1, f2, and f3????





Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Query Error & Run-Time Error 3022 DavidWE Access 1 July 31st, 2008 11:17 AM
DataGrid renders different on different machines GertFrost ASP.NET 2.0 Basics 1 June 19th, 2007 03:34 PM
DataGrid renders different on different machines GertFrost ASP.NET 2.0 Professional 1 May 25th, 2006 10:21 PM
dw renders my css when previewed in browser? jakewilliamson Dreamweaver (all versions) 5 March 21st, 2005 05:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.