Cannot Find Error on this ASP

M

M P

Hi Team!

Hope that you could help me! Its been days since I made this script but I
cannot fix the problem! IE is prompting me that there is a Syntax Error but
it seems that the syntax is OK! Can you help me find the problem?

Note the fields PartNo and ItemDesc is the only text data type on my MS
Access database.


<%
Dim strSQL

Set conn= Server.CreateObject("ADODB.Connection")
conn.Open "FileDSN=dsn.dsn"
strSQL= "INSERT INTO tblItems
(PartNo,ItemDesc,Category,MinStockLevel,Cost,Currency) "
strSQL= strSQL & "Values('" & Request.Form("txtPN") & "', '"
strSQL= strSQL & Request.Form("txtItemDesc") & "', "
strSQL= strSQL & Request.Form("txtCategory") & ", "
strSQL= strSQL & Request.Form("txtMinStock") & ", "
strSQL= strSQL & Request.Form("txtCost") & ", "
strSQL= strSQL & Request.Form("txtCurrency") & ")"

conn.Execute strSQL

conn.Close

%>
 
S

Steven Burn

I could be wrong but, the error appears to be with the following 2 lines;

<second line>
strSQL= strSQL & "Values('" & Request.Form("txtPN") & "', '"

<last line>
strSQL= strSQL & Request.Form("txtCurrency") & ")"

You've got a ' after Values( and at the end with the comma, but there's no
matching one at the end of the last line (closing the ")" )

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Disclaimer:
I know I'm probably wrong, I just like taking part ;o)
 
K

Ken Schaefer

Before:
conn.Execute strSQL

Do this:

<%
Response.Write(strSQL)
Response.End

conn.Execute strSQL
%>

and you will see your SQL statement printed to the screen. Examine it for
errors, or post it here.

Cheers
Ken


: Hi Team!
:
: Hope that you could help me! Its been days since I made this script but I
: cannot fix the problem! IE is prompting me that there is a Syntax Error
but
: it seems that the syntax is OK! Can you help me find the problem?
:
: Note the fields PartNo and ItemDesc is the only text data type on my MS
: Access database.
:
:
: <%
: Dim strSQL
:
: Set conn= Server.CreateObject("ADODB.Connection")
: conn.Open "FileDSN=dsn.dsn"
: strSQL= "INSERT INTO tblItems
: (PartNo,ItemDesc,Category,MinStockLevel,Cost,Currency) "
: strSQL= strSQL & "Values('" & Request.Form("txtPN") & "', '"
: strSQL= strSQL & Request.Form("txtItemDesc") & "', "
: strSQL= strSQL & Request.Form("txtCategory") & ", "
: strSQL= strSQL & Request.Form("txtMinStock") & ", "
: strSQL= strSQL & Request.Form("txtCost") & ", "
: strSQL= strSQL & Request.Form("txtCurrency") & ")"
:
: conn.Execute strSQL
:
: conn.Close
:
: %>
:
:
 
L

Lain

Hi M

Assuming you've copied and pasted this text, then the issue will be with your SQL string (starting with "strSQL ="). On this line you've missed the ending " & _, so it should look like this

strSQL= "INSERT INTO tblItems" &

and on each line of the string thereafter you have the trailing ", but not the required & _. This is how it should be

Set conn= Server.CreateObject("ADODB.Connection"
conn.Open "FileDSN=dsn.dsn
strSQL= "INSERT INTO tblItems" &
(PartNo,ItemDesc,Category,MinStockLevel,Cost,Currency) " &
strSQL= strSQL & "Values('" & Request.Form("txtPN") & "', '" &
strSQL= strSQL & Request.Form("txtItemDesc") & "', " &
strSQL= strSQL & Request.Form("txtCategory") & ", " &
strSQL= strSQL & Request.Form("txtMinStock") & ", " &
strSQL= strSQL & Request.Form("txtCost") & ", " &
strSQL= strSQL & Request.Form("txtCurrency") & ")

In any command or string in VBScript, if you want to break a single line statement up from one line into multiple, you need to add a underscore (_) to the end of the line. This is the character VBScript uses to indicate the next line is a continuum of the current line

Cheer
Lai
 
J

jon

Ensure that the non-text values do actually contain a numeric value, otherwise you will be posting back a blank - which will cause an error. Try adding a check function to ensure this i.e.

Function ConvNo(pNo)

If IsNumeric(pNo) Then
ConvNo = Cdbl(pNo)
Else
ConvNo = 0
End if

End Function

Then call this on each of the numeric field as:

ConvNo(Request.Form("txtCurrency"))

This will ensure that 0 is passed rather than "" on an expected numeric entry.



**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,128
Latest member
ElwoodPhil
Top