Click to See Complete Forum and Search --> : Asp Error, Help!!!!


JJ9867
04-19-2003, 08:49 PM
Hi I'm new at Asp and last weekend I put together a page to take form input and put it into an access database. After solving a few simple errors I hit a brick wall.

The error message is:
Error Type:
Microsoft JET Database Engine (0x80040E14)
Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'.
/test2.asp, line 75

The code for this is:

<%@ LANGUAGE = JScript %>
<html>
<head>
<title>The Asp Test Page</title>
</head>
<body>
<%
// declare variables
var name;
var bname;
var phone;
var email;
var address;
var city;
var state;
var zip;
var key = 2;

//initialize variables
name = Request.Form("name");
bname = Request.Form("bname");
phone = "(" + Request.Form("phonea") + ") " + Request.Form("phoneb") + "-" + Request.Form("phonec");
if (Request.Form("email") == null)
{
email = "None";
}
else
{
email = Request.Form("email");
}
address = Request.Form("address");
city = Request.Form("city");
state = Request.Form("state");
zip = Request.Form("zip");

// Create database access variables
var oConn;
var oRs;
var filePath;

// Map the database Path

filePath = Server.MapPath("test.mdb");

// create the connection

oConn = Server.CreateObject("ADODB.Connection");
oConn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath);

oRs = oConn.Execute("SELECT CustomerId From customers");

if (oRs.eof)
{
key = 0;
}
else
{

var temp;
var index = 0;

while (!oRs.eof)
{
if(oRs(0) > key){
key = oRs(0);
}
oRs.MoveNext();
}
}

key++;

//Populate the DataBase

oConn.Execute("INSERT INTO customers (CustomerId, Name, CompanyName, PhoneNumber, EmailAddress, Address, City, State, ZipCode) values ('"& key &"', '"& name &"', '"& bname &"', '"& phone &"', '"& email &"', '"& address &"', '"& city &"', '"& state &"', '"& zip &"')");


oConn.Close;
oConn = 0;
%>
Thank you for submitting the information to whatever this database is.<br>
Click here to see the database:<a href="main.asp">The main database</a>
</body>
</html>

I'm running IIS on a windows xp machine.
Any advice would be great,
Thanks
JJ

potemkin
04-22-2003, 05:45 PM
Hey. I just have a suggestion. When you write ASP you should use Dim instead of Var to declare your variables. Since ASP uses VBScript, and it is natural for VB to use Dim, you should be following the rules.

potemkin
04-22-2003, 08:15 PM
Oh, sorry. I did miss that one.
But VBScript is the native script of ASP, it is like the base, isn't it?

JJ9867
04-23-2003, 08:57 PM
Hi again,

I prefer Java Script (Jscript) because it resembles C++
My language of choice.

Anyway does anyone have any suggestions to fix that error?

JJ9867
04-25-2003, 07:09 AM
No I have client side javascript to parse the fields for any illegal characters. I also checked the values coming into the asp page to make sure they were legel. The only punctuation I have is a period and an @ sign in the E-mail address.

JJ9867
04-26-2003, 12:11 PM
I looked at the link you posted I guess I will have to get a book on Ado cause I still don't understand what is causing the error. Can you just tell me the correct syntax and I will go from there?

Thanks
JJ