Wrox Programmer Forums
|
ASP Pro Code Clinic As of Oct 5, 2005, this forum is now locked. No posts have been deleted. Please use "Classic ASP Professional" at: http://p2p.wrox.com/forum.asp?FORUM_ID=56 for discussions similar to the old ASP Pro Code Clinic or one of the other many remaining ASP and ASP.NET forums here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Pro Code Clinic 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 June 2nd, 2004, 06:04 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default Recordcount problem

I want to display the recordcount within the loop, but it give following error.

Error Type:
ADODB.Recordset (0x800A0E79)
Operation is not allowed when the object is open.
/dcilweb/sas/apprec/sant2.asp, line 97

display records where approvals.empno='"&rs2("empno")&"' and also count records of each empno ?

I use want to use recordset with in the loop, like following
ie each empno count records which received from the second query ie and display the records.


<%

set cn=server.CreateObject("adodb.connection")
set rs=server.CreateObject("adodb.recordset")
cn.ConnectionString="" // connection string
cn.Open

ssql2="select distinct approvals.empno,employees.name from approvals,employees where approvals.empno=employees.empno order by employees.name"

set rs2=cn.Execute(ssql2)

do while rs2.eof=false

rs.Open "select approvals.rec_id,approvals.empno,employees.name from approvals,employees where approvals.empno=employees.empno and approvals.empno='"&rs2("empno")&"' order by employees.name",cn,3,1

Response.Write("<tr colspan=10>")
Response.Write("<td colspan=10 align=left size=2>" &"<strong>"& rs.RecordCount &"</strong>"& "</td>") // here is give error, how can use recordcount within the loop?

do while rs.eof=false

Response.Write("<tr>")
Response.Write("<td>" & rs("empno") & "</td>")
Response.Write("<td align=left>" & rs("name") & "</td>")
.....


rs.movenext
loop

rs2.movenext
loop

%>


regards.

Mateen



 
Old June 2nd, 2004, 06:26 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Oh come on. This is basic ASP / ADO stuff. A 0.2 second search on Google will tell you exactly why this problem occurs and how you can fix it. In fact, just staring at the error message for 2 seconds will tell you how to fix it.

The ASP Pro Code Clinic forum is not meant as your on-line debugger. That is, IMO, you should do some research yourself before you copy and paste your code and errors so we can fix them for you. Use Google, use the MSDN site, use various other ASP related sites. And, most importantly, use the Pro Code Clinic for "pro questions". Stuff like tricky design issues, complicated logic etc, and not for "easy programming problems".

Sorry if i sound a bit hard, but IMO it's important to keep this forums a bit on-topic. Pro forums are for pro questions; the Beginning* forums are for easy questions.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old June 2nd, 2004, 11:37 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok

thanks.



 
Old June 3rd, 2004, 01:00 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 171
Thanks: 0
Thanked 1 Time in 1 Post
Default

Oh come on Imar. Take it easy on the poor soul. Mateen is just seeking a little guidance. Try this out Mateen. It will give you the number of the record that you are on. Is that what you're looking for?


do while not rs.eof
RecordCount = RecordCount + 1

<tr>
  <td><%=RecordCount%></td>
</tr>
<tr>
  <td><%=rs("EmpNo")%></td>
</tr>

rs.movenext
loop


 
Old June 3rd, 2004, 02:47 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks.

there should be one separate ASP Beginning forum in the
http://p2p.wrox.com

regards.



 
Old June 3rd, 2004, 03:05 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Well, usually I do try to take it easy on "poor souls". However as far as I can see, Mateen has been around here for quite some time.
If I browse through his post history, I see a lot of questions that should have been fixed by a script debugger and Google, not by fellow programmers on a forum.

If you're completely new at P2P, I can imagine you ask beginners questions, and I can also imagine you ask them in the wrong forum. However, if you have been around here for a year, posting almost 300 messages in ASP related forums, I can't understand why we should fix an "Operation is not allowed when the object is open" error while Google will tell you what the problem is in a few seconds.
The description of this forum says: "Do you have a tough advanced ASP code problem to solve?" which, IMO, doesn't match with the original topic. Keeping forums on topic is in everyone's interest. If advanced forums are flooded with easy questions, people watching these forums (including myself) may be less inclined to answer those questions.

Mateen: I don't try to be rude or anything. It's just frustrating to see the same type of questions asked over and over again, especially if you could easily fix them yourself with a little bit of research on freely available resources.....

Maybe you should try this forum: ASP Web How-To. But even there, IMHO, you should try to fix some of the problems yourself before you post there.

Cheers,

Imar
 
Old June 3rd, 2004, 06:28 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 231
Thanks: 0
Thanked 0 Times in 0 Posts
Default

OK Mateen, here are a few pointers to help you out:
  • The problem is NOT with the rs.RecordCount line. I am guessing that Dave's suggestion did not help you because you don't want to know how far through the recordset you are, you want to know the total number of records in the recordset.
As a side note on a different point, if you want to find out how far through the recordset you are, you don't need to increment a counter, you can use the recordset's .AbsolutePosition property if you are cycling through the recordset returning every record in the order they were generated. But this will not help you Mateen, you need to look elswhere in your code.
  • Secondly, don't forget to close your recordsets once you have finished using them.
  • And finally, try Imar's suggestion of using Google or MSDN, here is the query I typed into Google.co.uk ADO Operation not allowed when object open and the first result returned (ADO Errors ()) was from the MSDN library and provided the answer to your problem.
Remember that if the error does not seem to be connected with the line you think created the error, the problem is probably on a different line. Try and get more familiar with ADO (and ASP for that matter), there are plenty of on-line resources that will teach you just about anything related to both topics, not to mention that there are literally hundreds of books on the subjects as well, ranging from absolute beginner to very advanced specific areas.

Regards
Owain Williams
 
Old June 5th, 2004, 05:10 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for comments.
you says right that I should be fixed by a script debugger
before posting. I try to fix but not success I post the message
to forum, I assume that in the forum I will learn more.
secondly I develop program (web base) self study, I have only
books and Forum. sometime book take more time, hence I post the problem.

When I post (recordset) problem, after that I was remove the error.

regards.

Mateen







Similar Threads
Thread Thread Starter Forum Replies Last Post
Help RecordCount jpaul Pro VB Databases 1 January 29th, 2008 01:46 PM
Recordset.recordcount = -1 Huss Classic ASP Databases 0 February 17th, 2007 04:41 AM
RecordCount dpkbahuguna Beginning VB 6 9 March 23rd, 2006 01:16 AM
RecordCount property doesn't work eapsokha Classic ASP Databases 6 February 10th, 2005 01:28 PM
RecordCount in DataGrid and Excel AyatKh ASP.NET 1.x and 2.0 Application Design 1 March 22nd, 2004 04:23 PM





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