DB data insertion: No Luck Frustrated Newbie

J

Jim

I'm still trying to get data to write to an access database. I've gove over
many examples of code but all the examples I've gone over and been directed
to have not given me strait answers.

I have an access called test.mdb located within the c:\inetpub\wwwroot\
folder where my other .htm and .asp docs are going. The database has a
single table called names. The fields within names are: fName, lName, and
zip

The code for dbtest.asp:

<html>
<head>
<title>dbsumbit</title>
</head>
<body>

<%

Dim cst,Conn,fName,lName,Zip

fName = Request.Form("firstname")
lName = Request.Form("lastname")
Zip = Request.Form("zipcode")

cst = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath("/c:\inetpub\wwwroot\test.mdb")
set conn = CreateObject("ADODB.Connection")
conn.open cst

Conn.execute("INSERT INTO names VALUES fName='" & fName & "','" & lName &
"','" & Zip & "'")

%>
</body>
</html>

The above code is just one of my many attempts at making this thing work.
I've tried many different coding examples and methods and none of them have
worked. Of course, I don't know what I'm doing so that's why I'm here.

The code for my form (form.htm) that directs to dbtest.mdb after the submit
button is pressed:

<html>
<head>
<title>Untitled</title>
</head>

<body>

<form method="post" action="dbtest.asp">
<input type="text" name="firstname">
<input type="text" name="lastname">
<input type="text" name="zip">
<input type="Submit" name="Submit" value="Send It!">
</form>


</body>
</html>


When I click the submit button, it redirects to dbtest.mdb and I get this
error in the Internet Explorer window. The Line 22, Column 73 referrs to the
last character in the long asp line of code: Conn.execute("INSERT INTO
names VALUES fName='" & fName & "','" & lName &


HTTP 500.100 - Internal Server Error - ASP error
Internet Information Services

----------------------------------------------------------------------------
----

Technical Information (for support personnel)

a.. Error Type:
Microsoft VBScript compilation (0x800A03EA)
Syntax error
/dbtest.asp, line 22, column 73


b.. Browser Type:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)

c.. Page:
POST 60 bytes to /dbtest.asp

d.. POST Data:
firstname=John&lastname=Doe&zip=90210&Submit=Send+It%21
 
R

Ray at

Try:


Change:
cst = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath("/c:\inetpub\wwwroot\test.mdb")

To:
cst = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath("/test.mdb")


Change line 73 to:
Conn.execute "INSERT INTO [names] VALUES fName='" & fName & "','" & lName &
"','" & Zip & "'", ,129


Ray at work
 
P

Paul Bobrowski

I'd also have to agree with the Server.MapPath change. The MapPath function
will return the location on the local harddrive from a webpage path so
Server.MapPath("/test.mdb") should evaluate to "c:\inetpub\wwwroot\test.mdb"

I'd personnally would try changing the SQL execute to:
Conn.execute "INSERT INTO names(fName, lName, Zip) VALUES('" & fName & "','"
& lName & "','" & Zip & "')"

Notice the removal of the ()'s are gone from Conn.execute(). This is
because you are just inserting and you aren't handling a return value. You
could do a:
retval = Conn.execute("INSERT INTO names(fName, lName, Zip) VALUES('" &
fName & "','" & lName & "','" & Zip & "')"); however, but it's not
necessary.

Also while your other SQL statement may have been valid. using the standard
insert into <table>(<col1>,<col2>) values(<val1>, <val2>) may help get
around any issues with the provider you are using.


Ray at said:
Try:


Change:
cst = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath("/c:\inetpub\wwwroot\test.mdb")

To:
cst = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath("/test.mdb")


Change line 73 to:
Conn.execute "INSERT INTO [names] VALUES fName='" & fName & "','" & lName &
"','" & Zip & "'", ,129


Ray at work





Jim said:
I'm still trying to get data to write to an access database. I've gove over
many examples of code but all the examples I've gone over and been directed
to have not given me strait answers.

I have an access called test.mdb located within the c:\inetpub\wwwroot\
folder where my other .htm and .asp docs are going. The database has a
single table called names. The fields within names are: fName, lName, and
zip

The code for dbtest.asp:

<html>
<head>
<title>dbsumbit</title>
</head>
<body>

<%

Dim cst,Conn,fName,lName,Zip

fName = Request.Form("firstname")
lName = Request.Form("lastname")
Zip = Request.Form("zipcode")

cst = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath("/c:\inetpub\wwwroot\test.mdb")
set conn = CreateObject("ADODB.Connection")
conn.open cst

Conn.execute("INSERT INTO names VALUES fName='" & fName & "','" & lName &
"','" & Zip & "'")

%>
</body>
</html>

The above code is just one of my many attempts at making this thing work.
I've tried many different coding examples and methods and none of them have
worked. Of course, I don't know what I'm doing so that's why I'm here.

The code for my form (form.htm) that directs to dbtest.mdb after the submit
button is pressed:

<html>
<head>
<title>Untitled</title>
</head>

<body>

<form method="post" action="dbtest.asp">
<input type="text" name="firstname">
<input type="text" name="lastname">
<input type="text" name="zip">
<input type="Submit" name="Submit" value="Send It!">
</form>


</body>
</html>


When I click the submit button, it redirects to dbtest.mdb and I get this
error in the Internet Explorer window. The Line 22, Column 73 referrs to the
last character in the long asp line of code: Conn.execute("INSERT INTO
names VALUES fName='" & fName & "','" & lName &


HTTP 500.100 - Internal Server Error - ASP error
Internet Information Services

--------------------------------------------------------------------------
--
----

Technical Information (for support personnel)

a.. Error Type:
Microsoft VBScript compilation (0x800A03EA)
Syntax error
/dbtest.asp, line 22, column 73


b.. Browser Type:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)

c.. Page:
POST 60 bytes to /dbtest.asp

d.. POST Data:
firstname=John&lastname=Doe&zip=90210&Submit=Send+It%21
 
B

Bob Barrows [MVP]

Paul said:
I'd also have to agree with the Server.MapPath change. The MapPath
function will return the location on the local harddrive from a
webpage path so Server.MapPath("/test.mdb") should evaluate to
"c:\inetpub\wwwroot\test.mdb"

I'd personnally would try changing the SQL execute to:
Conn.execute "INSERT INTO names(fName, lName, Zip) VALUES('" & fName
& "','" & lName & "','" & Zip & "')"

Notice the removal of the ()'s are gone from Conn.execute(). This is
because you are just inserting and you aren't handling a return
value.

While this is a vailid reason, as long as there is a single argument, the
parentheses won't hurt. The REAL reason for not using parentheses is because
more than one argument should be passed to the Execute method: you should
ALWAYS supply the CommandType argument:

Conn.execute "INSERT INTO names(fName, lName, Zip) VALUES('" & fName & "','"
& lName & "','" & Zip & "')",,1) '1=adCmdText

While there is a performance benefit to including the CommandType argument,
that is not the main benefit (the performance benefit is not significant).
While rare, ADO can misguess the CommandTyp, leading to problems that are
virtually impossible to debug. ALWAYS tell ADO the command type.

Bob Barrows
 
B

Bob Barrows [MVP]

Bob said:
While this is a vailid reason, as long as there is a single argument,
the parentheses won't hurt. The REAL reason for not using parentheses
is because more than one argument should be passed to the Execute
method: you should ALWAYS supply the CommandType argument:

Conn.execute "INSERT INTO names(fName, lName, Zip) VALUES('" & fName
& "','" & lName & "','" & Zip & "')",,1) '1=adCmdText
Sigh!
And of course (!) I left in the end parenthesis! It should be:

Conn.execute "INSERT INTO names(fName, lName, Zip) VALUES('" & fName & "','"
& lName & "','" & Zip & "')",,1 '1=adCmdText
 
R

Ray at

I'd personnally would try changing the SQL execute to:
Conn.execute "INSERT INTO names(fName, lName, Zip) VALUES('" & fName & "','"
& lName & "','" & Zip & "')"

I didn't even notice that the sql command was off. I'm mortified! :[

Ray at home
 

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,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top