|
 |
asp_web_howto thread: Updating a database using the results of a querystring
Message #1 by "Willington, David" <jdaw@o...> on Sat, 15 Sep 2001 12:26:24 +0100
|
|
Dear All
I've generated a form based on the fields of a database
using ASP to get the database fields. The results of this
form are sent to a second ASP page so that the results of
the querystring are used to identify the database fields and
update the database. The two pages are
To generate the form
<%
option explicit
dim objrs, strconnect
%>
<!-- #include file = "dblink.asp" -->
<%
'Get information from database to define field headers
set objrs = server.createobject("ADODB.recordset")
objrs.open "SELECT * FROM contacts", strconnect, 0, 1, 0
%>
<p>Use this form to add a new school to the database.</p>
<form method="GET" action="addschool.asp">
<table border="0" width="500">
<%
Dim fldF
For each fldF in objrs.Fields
If fldF.name <> "ID" then
response.write "<tr> <td width='100'>" & fldF.name &
"</td>"
response.write "<td width='400'><input type='text'
name='" & fldF.name & "' size='50'></td>"
response.write "</tr>"
Else
End if
next
%>
</table>
<p><input type="submit" value="Submit" name="B1"><input
type="reset" value="Reset" name="B2"></p>
</form>
<p> </p>
To update the database based on the querystring
<%
option explicit
dim objrs, strconnect
%>
<!-- #include file = 'dblink.asp' -->
<%
dim Item
set objrs = server.createobject("ADODB.recordset")
objrs.open "SELECT * FROM contacts", strconnect, 3, 2, 0
objrs.movelast
objrs.addnew
'update the recordset
For each Item in request.querystring
objrs(Item) = request.querystring(Item)
Next
objrs.update
objrs.close
%>
The form seems fine, but the problem seems to be in
objrs(Item) = request.querystring(Item),
which generates a typemismatch error.
Thanks to anyone who can help
David Willington
Message #2 by "Coffey, Dana" <dcoffey@B...> on Mon, 17 Sep 2001 07:22:27 -0700
|
|
to begin
objrs(Item) = request.querystring(Item)
s/b
objrs("Item") = request.querystring(Item)
Also, I would reccommend using the "POST" method in your form, instead of
"GET" and then
request.form
Also, when opening your recordset, you should avoid "magic numbers". More
on this can be found at Ken's site: www.adopenstatic.com .
Right before you run the query, trying doing a response.write of both the
values retrieved from the form, and your sql statement as well.
You will also notice, that in your loop to update, you have placed the
update statement OUTSIDE the loop. You want to move it to within the loop,
as you want to do an update on each item in the set.
PS... This might be better done using the connection object and an "insert"
statement.
Hope this helps. :)
d
-----Original Message-----
From: Willington, David [mailto:jdaw@o...]
Sent: Saturday, September 15, 2001 7:26 AM
To: ASP Web HowTo
Subject: [asp_web_howto] Updating a database using the results of a
querystring
Dear All
I've generated a form based on the fields of a database
using ASP to get the database fields. The results of this
form are sent to a second ASP page so that the results of
the querystring are used to identify the database fields and
update the database. The two pages are
To generate the form
<%
option explicit
dim objrs, strconnect
%>
<!-- #include file = "dblink.asp" -->
<%
'Get information from database to define field headers
set objrs = server.createobject("ADODB.recordset")
objrs.open "SELECT * FROM contacts", strconnect, 0, 1, 0
%>
<p>Use this form to add a new school to the database.</p>
<form method="GET" action="addschool.asp">
<table border="0" width="500">
<%
Dim fldF
For each fldF in objrs.Fields
If fldF.name <> "ID" then
response.write "<tr> <td width='100'>" & fldF.name &
"</td>"
response.write "<td width='400'><input type='text'
name='" & fldF.name & "' size='50'></td>"
response.write "</tr>"
Else
End if
next
%>
</table>
<p><input type="submit" value="Submit" name="B1"><input
type="reset" value="Reset" name="B2"></p>
</form>
<p> </p>
To update the database based on the querystring
<%
option explicit
dim objrs, strconnect
%>
<!-- #include file = 'dblink.asp' -->
<%
dim Item
set objrs = server.createobject("ADODB.recordset")
objrs.open "SELECT * FROM contacts", strconnect, 3, 2, 0
objrs.movelast
objrs.addnew
'update the recordset
For each Item in request.querystring
objrs(Item) = request.querystring(Item)
Next
objrs.update
objrs.close
%>
The form seems fine, but the problem seems to be in
objrs(Item) = request.querystring(Item),
which generates a typemismatch error.
Thanks to anyone who can help
David Willington
Message #3 by "Coffey, Dana" <dcoffey@B...> on Mon, 17 Sep 2001 07:31:31 -0700
|
|
oops...
forgive me..
objrs(item) = request.querystring(Item) is fine....
however... it might be choking on that line....
-----Original Message-----
From: Coffey, Dana
Sent: Monday, September 17, 2001 10:22 AM
To: ASP Web HowTo
Subject: [asp_web_howto] RE: Updating a database using the results of a
querystring
Also, I would reccommend using the "POST" method in your form, instead of
"GET" and then
request.form
Also, when opening your recordset, you should avoid "magic numbers". More
on this can be found at Ken's site: www.adopenstatic.com .
Right before you run the query, trying doing a response.write of both the
values retrieved from the form, and your sql statement as well.
You will also notice, that in your loop to update, you have placed the
update statement OUTSIDE the loop. You want to move it to within the loop,
as you want to do an update on each item in the set.
PS... This might be better done using the connection object and an "insert"
statement.
Hope this helps. :)
d
-----Original Message-----
From: Willington, David [mailto:jdaw@o...]
Sent: Saturday, September 15, 2001 7:26 AM
To: ASP Web HowTo
Subject: [asp_web_howto] Updating a database using the results of a
querystring
Dear All
I've generated a form based on the fields of a database
using ASP to get the database fields. The results of this
form are sent to a second ASP page so that the results of
the querystring are used to identify the database fields and
update the database. The two pages are
To generate the form
<%
option explicit
dim objrs, strconnect
%>
<!-- #include file = "dblink.asp" -->
<%
'Get information from database to define field headers
set objrs = server.createobject("ADODB.recordset")
objrs.open "SELECT * FROM contacts", strconnect, 0, 1, 0
%>
<p>Use this form to add a new school to the database.</p>
<form method="GET" action="addschool.asp">
<table border="0" width="500">
<%
Dim fldF
For each fldF in objrs.Fields
If fldF.name <> "ID" then
response.write "<tr> <td width='100'>" & fldF.name &
"</td>"
response.write "<td width='400'><input type='text'
name='" & fldF.name & "' size='50'></td>"
response.write "</tr>"
Else
End if
next
%>
</table>
<p><input type="submit" value="Submit" name="B1"><input
type="reset" value="Reset" name="B2"></p>
</form>
<p> </p>
To update the database based on the querystring
<%
option explicit
dim objrs, strconnect
%>
<!-- #include file = 'dblink.asp' -->
<%
dim Item
set objrs = server.createobject("ADODB.recordset")
objrs.open "SELECT * FROM contacts", strconnect, 3, 2, 0
objrs.movelast
objrs.addnew
'update the recordset
For each Item in request.querystring
objrs(Item) = request.querystring(Item)
Next
objrs.update
objrs.close
%>
The form seems fine, but the problem seems to be in
objrs(Item) = request.querystring(Item),
which generates a typemismatch error.
Thanks to anyone who can help
David Willington
|
|
 |