Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Good SQL Statement Excute No Go

Status
Not open for further replies.

JordanR

Technical User
Oct 3, 2002
182
US
I have a sql statement that looks correct when I print it out but when I execute it I get a Syntax error:
Syntax error in INSERT INTO statement.
I have been getting this problem all week with other insert, update statements and it is frustrating.
Please help? here is the code
<%
Set conn=Server.CreateObject(&quot;ADODB.Connection&quot;)
conn.open (&quot;ABFAtlanta&quot;)

myArray=split(request.form(&quot;MultiSelect&quot;),&quot;,&quot;)
for i=0 to Ubound(myArray)
strSql=&quot;INSERT tblProductcolors (color) Values ('&quot; & myArray(i) & &quot;')&quot;
SET pcolors = conn.execute(strSql)
response.Write(strSql)
Next
conn.close
set conn=nothing
%>
 
What happens if you change
SET pcolors = conn.execute(strSql)
to just
conn.execute(strSql)
 
When you post a multiple select the form field it's already an array you dont need to split it up.
you can walk tha array with
for i=0 to request.form(&quot;MultiSelect&quot;).Count-1
and get values with
request.form(&quot;MultiSelect&quot;).Items(i)
Also your code looks ok but you can have 1 posible error: could have a quote character.

Try with this
Code:
strSql=&quot;INSERT tblProductcolors (color) Values ('&quot; & Replace(myArray(i),&quot;'&quot;,&quot;''&quot;) & &quot;')&quot;

________
George, M
 
I see nothing wrong with your code. Check the permissions on your database. INSERT statements require write access and you will get this error if write permissions are not set.

FYI:
On the the line: SET pcolors = conn.execute(strSql)
You can simply shorten this to: conn.execute(strSql)
INSERT and DELETE statement don't return a anything.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top