Wrox Programmer Forums
|
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
 
Old March 19th, 2006, 01:41 PM
Authorized User
 
Join Date: Mar 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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!
 
Old March 19th, 2006, 07:13 PM
Wrox Technical Editor
 
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Your problem:

the Record Set (rs1) has been opened, but you didn't define a connection string...

rs1.Open sqlrecord, conn

- A.Kahtava
 
Old March 19th, 2006, 07:15 PM
Wrox Technical Editor
 
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Links of interest:

ADO Recordset: http://www.w3schools.com/ado/ado_recordset.asp

- A.Kahtava
 
Old March 19th, 2006, 11:37 PM
Authorized User
 
Join Date: Mar 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

 
Old March 20th, 2006, 12:11 AM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

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
 
Old March 20th, 2006, 12:14 AM
Wrox Technical Editor
 
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old March 20th, 2006, 12:15 AM
Wrox Technical Editor
 
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

LOL... Too much.. :)
I was 3 minutes too late..

- A.Kahtava
 
Old March 20th, 2006, 12:24 AM
Authorized User
 
Join Date: Mar 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks much. Looks like I'm all set for now :D

 
Old March 20th, 2006, 12:30 AM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

LOL indeed - another example of how useful this forum and its members are. sswingle - you joined the good one.

Wind is your friend
Matt





Similar Threads
Thread Thread Starter Forum Replies Last Post
choose specific record ar555 Dreamweaver (all versions) 12 January 12th, 2007 01:04 PM
displaying html in a .aspx webpage badgolfer ASP.NET 1.0 and 1.1 Basics 0 February 22nd, 2005 10:50 AM
URGENT: Problem in displaying chart on webpage spacy Crystal Reports 6 July 16th, 2004 04:07 AM
Displaying options specific to the admin Smack715 Classic ASP Basics 11 June 23rd, 2004 08:33 AM
Link to a specific record rexecampbell Classic ASP Basics 2 April 7th, 2004 01:40 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.