Solved

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

Posted on 2004-08-04
7
670 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
Comment Utility
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
Comment Utility
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
Comment Utility
Missing space before "VALUES"

try
AddResults = "INSERT INTO [Output] (ID,PartOut,QtyOut) VALUES ('" & IDVar & "','" & PartVar & "','" & QtyVar& "')"
BOMDBConnection.execute(AddResults)
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 16

Expert Comment

by:golfDoctor
Comment Utility
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
Comment Utility
0
 
LVL 16

Author Comment

by:legalsrl
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now