Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access ASP
|
Access ASP Using ASP with Microsoft Access databases. For Access questions not specific to ASP, please use the Access forum. For more ASP forums, please see the ASP forum category.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access ASP 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 April 16th, 2004, 12:01 AM
Registered User
 
Join Date: Feb 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default can't display record from table.

I have a table in MS Access shown below. I am able to display the score for quiz_id=1. However, it will not display scores when I attempt to write sql statements (shown below) for 2, 3, and 4. Please advise..

MS ACCESS TABLE:
StudentTable

StudentID quiz_id Score
123456789 1 100
123456789 2 75
123456789 3 45
123456789 4 75

<%
sqltext1 = "SELECT * FROM StudentTable WHERE StudentID='" & Session("username") & "'"
oRS.Open sqltext1, oConn

IF oRS("quiz_id") = "1" Then
Response.Write "" & oRS("Score") & "%" & ""
Else

Response.Write "0"

End If
oRs.Close
%>


</td>
<td width="125" align="center">

<%
sqltext2 = "SELECT * FROM StudentTable WHERE StudentID='" & Session("username") & "'"
oRS.Open sqltext1, oConn

IF oRS("quiz_id") = "2" Then
Response.Write "" & oRS("Score") & "%" & ""
Else

Response.Write "0"

End If
oRs.Close
%>

Repeat for 3 and 4.
The only score that displaysis when quiz_id = 1

 
Old April 16th, 2004, 02:40 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

It looks like you don't quite understand how recordsets work, so let's go through your code and explain what's happening.

After this first bit of code is run:
Code:
sqltext1 = "SELECT * FROM StudentTable WHERE StudentID='" & Session("username") & "'"
oRS.Open  sqltext1, oConn
you have a recordset (oRS) which contains all 4 records, and its automatically positioned at the first record, so when you do the test:
Code:
IF oRS("quiz_id") = "1" Then
the result is TRUE and so the score is written to the browser by your next line of code.

So, when you repeat the code:
Code:
sqltext2 = "SELECT * FROM StudentTable WHERE StudentID='" & Session("username") & "'"
oRS.Open  sqltext1, oConn
you again get a recordset containing all 4 records which is positioned at the first record, so this time your test:
Code:
IF oRS("quiz_id") = "2" Then
fails.

So, can you see that instead of repeating the SQL, all you need to do is oRS.MoveNext? That will position the recordset to the second record (the one with quizid=2). Personally I would add an ORDER BY clause to the SQL to ensure you always get the records back in the sequence you expect:
SELECT * FROM StudentTable WHERE StudentID='" & Session("username") & "' ORDER BY StudentID, quiz_id"

hth
Phil
 
Old April 16th, 2004, 07:48 AM
Registered User
 
Join Date: Feb 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Phil! Yes, I am new to asp. I will try your suggestion!

 
Old June 5th, 2004, 12:36 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 171
Thanks: 0
Thanked 1 Time in 1 Post
Default

Better late than never eh?

set oRS = server.createobject("adodb.recordset")
sqltext1 = "SELECT * FROM StudentTable WHERE StudentID='" & Session("username") & "'"
oRS.Open sqltext1, oConn
if not oRS.eof then
    do while not oRS.eof
    response.write "<tr><td>" & oRS("Score") & "%</td></tr>"
    oRS.movenext
    loop
end if
oRS.close
set oRS = nothing







Similar Threads
Thread Thread Starter Forum Replies Last Post
database record does not display magmo Classic ASP Basics 2 September 27th, 2007 03:46 PM
How do you display first record of a field only saf01 Crystal Reports 1 November 7th, 2005 07:49 AM
record display Ashleek007 Beginning PHP 1 July 22nd, 2005 01:40 PM
Display one database record Mikej00 Classic ASP Databases 1 December 1st, 2004 07:14 AM
Display a single record.. PLEASE HELP TnTandyO Classic ASP Databases 26 September 9th, 2003 10:34 AM





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