 |
| Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 19th, 2006, 01:41 PM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Displaying a specific record on a webpage
I am having trouble using a query in order to view a single record on a webpage
<%
If Len(Request.Form("id")) Then
Dim form_id, data_source, sql_delete, con, rs, sqlrecord, no, count, callback_id, rs1
form_id = CInt(Request.Form("id"))
data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
Server.MapPath("form.mdb")
form_id=id
sqlrecord= "Select * FROM users WHERE id="&form_id
Set rs1 = Server.CreateObject("ADODB.Recordset")
rs1.Open sqlrecord
The variable id is coming from the previous page's form, and is a primary key auto number in the database, so the number will only correspond to a single record.
My error is:
ADODB.Recordset error '800a0e7d'
The connection cannot be used to perform this operation. It is either closed or invalid in this context.
/showone.asp, line 24
Line 24 is rs1.Open sqlrecord
Anyone see what I'm doing wrong?
Thanks!
|
|

March 19th, 2006, 07:13 PM
|
|
Wrox Technical Editor
|
|
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Your problem:
the Record Set (rs1) has been opened, but you didn't define a connection string...
rs1.Open sqlrecord, conn
- A.Kahtava
|
|

March 19th, 2006, 11:37 PM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Excellent. That fixed part of the problem. Now it doesn't like my select statement. I get error:
Syntax error (missing operator) in query expression 'id='.
I have tried putting my variable in many different ways and nothing seems to work. If I manually put in an ID on the select statement, then it loads the correct record and everything works fine.
|
|

March 20th, 2006, 12:11 AM
|
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
|
|
is there a value in the variable form_id - looking at the error I would say this is your problem. (is id an integer field?) Its a good habbit to finish sql statement with trailing semi colons - this helps prevent SQL Injections (lets not go into that, google covers it well) I would write it like:
sqlrecord= "Select * FROM users WHERE id=" & form_id & ";"
Wind is your friend
Matt
|
|

March 20th, 2006, 12:14 AM
|
|
Wrox Technical Editor
|
|
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
What data type is id? Is it an int or a string?
If it's a string you need single quotes.
Example:
"SELECT * FROM users WHERE id = '" & form_id & "';"
- A.Kahtava
|
|

March 20th, 2006, 12:15 AM
|
|
Wrox Technical Editor
|
|
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
LOL... Too much.. :)
I was 3 minutes too late..
- A.Kahtava
|
|

March 20th, 2006, 12:24 AM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks much. Looks like I'm all set for now :D
|
|

March 20th, 2006, 12:30 AM
|
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
|
|
LOL indeed - another example of how useful this forum and its members are. sswingle - you joined the good one.
Wind is your friend
Matt
|
|
 |