Solved

INSERT INTO Syntax Error using ASP, VBScript, Advanced Server 2000

Posted on 2004-08-04
7
679 Views
Last Modified: 2008-02-01
Hi,

I am having one hell of a day trying to extract some records from an existing table in an existing database.  The idea behind this application is for a Manufacturing Client of mine who wants to decide to build 5 types of unit in one day and only wants 1 kitting list to feature the whole of day's requirements.

I am extracting the ParentPart, ComponentPart and Qty per fields using an SQL query.  That works fine and I can display all the items meeting the criteria, but when I try to add it to another seperate existing table, it just throws up the INSERT INTO syntax Errox on the line containing

The code below takes the 5 Parts and their Quantities from an htm file and extracts all the records meeting the criteria

<% @language="vbscript" %>

<%
Part1=Request.Form("Part1")
Part2=Request.Form("Part2")
Part3=Request.Form("Part3")
Part4=Request.Form("Part4")
Part5=Request.Form("Part5")
Qty1=Request.Form("Quantity1")
Qty2=Request.Form("Quantity2")
Qty3=Request.Form("Quantity3")
Qty4=Request.Form("Quantity4")
Qty5=Request.Form("Quantity5")

' Dimension my arrays and variables

 Dim BOMDBConnection,BOMDBConnectionOut
 Dim GetParts,GetParts1,GetParts2,GetParts3,GetParts4
 Dim AddParts,AddParts1,AddParts2,AddParts3,AddParts4
 Dim BOMdbresults,BOMdbresults1,BOMdbresults2,BOMdbresults3,BOMdbresults4
 Dim BOMdbpath,BOMdbpath1,BOMdbpath2,BOMdbpath3,BOMdbpath4

Set BOMDBConnection = Server.CreateObject("ADODB.Connection")

'  This section opens the Database for the connection, this works fine

BOMdbpath = server.mappath("/bom/fpdb")
connection = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & BOMdbpath & "\cbom.mdb"
BOMDBConnection.open (connection)      
                  
'  This section creates the Recordset to hold the information returned by the first query

set BOMdbresults = Server.CreateObject("ADODB.Recordset")
GetParts = "SELECT * FROM BOM WHERE ParentPart ='" & Part1 & "'"

'  This section runs the first query      

            set BOMdbresults = BOMDBConnection.execute(GetParts)
            if not BOMdbresults.EOF then
                  Response.Write(" Data for : " & Part1 & "<BR>")
                        while not BOMdbresults.EOF
                        Response.Write(" ID : " & BOMdbresults("ID") & " ")
                        Response.Write(" Component : " & BOMdbresults("Component")& " ")                        
                        Response.Write(" Quantity : " & BOMdbresults("Qty")& "<BR>")
                        set PartVar = BOMdbresults("Component")
                        set QtyVar = BOMdbresults("Qty")
                        set IDVar = BOMdbresults("ID")
                        response.write "THE QUERY IS : INSERT INTO Output (ID,PartOut,QtyOut)VALUES ('" & IDVar & "','" & PartVar & "','" & QtyVar& "')"

***** The above line generates the following output *********

THE QUERY IS : INSERT INTO Output (ID,PartOut,QtyOut)VALUES ('1627','HDW100088','4')

So the SQL query should be laid out in the line below correctly

' AddResults = "INSERT INTO Output (ID,PartOut,QtyOut)VALUES ('" & IDVar & "','" & PartVar & "','" & QtyVar& "')"
' BOMDBConnection.execute(AddResults)
BOMdbresults.movenext()
      wend
else
end if      

There's more below here, but the rest works

If I remove the ' from the BOMDBConnection.execute(AddResults) and above line, I get that irritating Syntax Error

Please help !!!

Thanks
Si

0
Comment
Question by:legalsrl
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 16

Expert Comment

by:golfDoctor
ID: 11716611
What are the datatypes of the fields, in your example they all must be text.

What is the exact error messgae?
0
 
LVL 15

Accepted Solution

by:
joeposter649 earned 125 total points
ID: 11716612
Perhaps "Output" is causing the problem because it's an ODBC reserved word.  Not sure if it would apply to OLE/DB.
0
 
LVL 26

Expert Comment

by:Hilaire
ID: 11716617
Missing space before "VALUES"

try
AddResults = "INSERT INTO [Output] (ID,PartOut,QtyOut) VALUES ('" & IDVar & "','" & PartVar & "','" & QtyVar& "')"
BOMDBConnection.execute(AddResults)
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 16

Expert Comment

by:golfDoctor
ID: 11716647
Here's reserved words: (doesn't appear to be the issue)

http://support.microsoft.com/default.aspx?scid=kb;EN-US;209187
0
 
LVL 15

Expert Comment

by:joeposter649
ID: 11716851
0
 
LVL 16

Author Comment

by:legalsrl
ID: 11723627
Thanks all for your help, the problem is now I get this

Error Type:
Microsoft JET Database Engine (0x80004005)
The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again.
/BOM/dbquery3.asp, line 54

If I run this asp script more than once.........this will be run on a daily basis, and will probably sometimes be run 2 or 3 times a day.

What I was going to do would be to run the import querys (5 of them for the 5 Bill of Materials needed), then write all of the details to the OutVar (it replaced Output) table, summarise the data on the Outvar table and output it, then delete the Outvar table

Surely this would stop this error happening if I clear the table after a successful run ?

Thanks again for your help
Si
0
 
LVL 16

Author Comment

by:legalsrl
ID: 11723880
Thanks for your help guys,

I managed to fix the last error by removing the primary key from the OutVar table

Works swimmingly now :-)


Si
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question