Hi
I am new to asp. I have managed to retrieve from an access database, but can't seem to get the simplest adding to database page working. The connection is fine, but it comes up with an 'error adding to db' error message
Can anyone spot the problem?? Here's the code
Thanks! Lee
<%@ Language=VBScript %>
<%Response.Buffer=True%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<body>
<!-- #include file = "ADOVBS.INC" -->
<%
Dim strname, strcity
Dim cndb, cmdaddtodatabase
Response.Expires=0
%>
<%
strname=Request.Form("name"
Response.Write strname
Set cndb = server.CreateObject("adodb.connection"
Set cmdaddtodatabase = server.CreateObject("adodb.command"
cndb.CommandTimeout = 15
cndb.CursorLocation = adUseServer
cndb.ConnectionString = "DSN=cjrcls"
on error resume next
cndb.open
if err <> 0 then
response.write "Error connecting to the database"
response.end
end if
With cmdaddtodatabase
.CommandTimeout = 15
set .ActiveConnection = cndb
.CommandType = adCmdText
.CommandText = "INSERT INTO testtable (name) VALUES ([pname]);"
.Parameters.Append(.CreateParameter ("pname",adVarChar,adParamInput,50,strname))
on error resume next
.Execute
if err.number <> 0 then
Response.Write "error adding to db"
Response.End
end if
End with
%>
</body>
</HTML>
I am new to asp. I have managed to retrieve from an access database, but can't seem to get the simplest adding to database page working. The connection is fine, but it comes up with an 'error adding to db' error message
Can anyone spot the problem?? Here's the code
Thanks! Lee
<%@ Language=VBScript %>
<%Response.Buffer=True%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<body>
<!-- #include file = "ADOVBS.INC" -->
<%
Dim strname, strcity
Dim cndb, cmdaddtodatabase
Response.Expires=0
%>
<%
strname=Request.Form("name"
Response.Write strname
Set cndb = server.CreateObject("adodb.connection"
Set cmdaddtodatabase = server.CreateObject("adodb.command"
cndb.CommandTimeout = 15
cndb.CursorLocation = adUseServer
cndb.ConnectionString = "DSN=cjrcls"
on error resume next
cndb.open
if err <> 0 then
response.write "Error connecting to the database"
response.end
end if
With cmdaddtodatabase
.CommandTimeout = 15
set .ActiveConnection = cndb
.CommandType = adCmdText
.CommandText = "INSERT INTO testtable (name) VALUES ([pname]);"
.Parameters.Append(.CreateParameter ("pname",adVarChar,adParamInput,50,strname))
on error resume next
.Execute
if err.number <> 0 then
Response.Write "error adding to db"
Response.End
end if
End with
%>
</body>
</HTML>