473,395 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

RE: Paging a recorset using a stored procedure

I'll make it easy on you...

The culprit is your line
Set rs = conn.Execute ("exec q_anagrafica")

When you open a recordset that way, you *always* get a forward-only cursor
(adForwardOnly) and a read-only recordset (adLockReadOnly).

Which means you can *NOT* then use RS.AbsolutePage or any of its kin.

So, as you said, you expected to use
RS.open conn,"exec q_anagrafica", 3
to get pagination, using the static cursor.

But now the culprit is that fact you are trying to use EXEC here and Access
doesn't really handle EXEC gracefully.

But luckily, an Access STORED QUERY is no different than a TABLE, when
viewed from a SQL query. So you can, instead, just do
RS.open conn,"SELECT * FROM q_anagrafica", 3
and it should all work.

Finally, a couple of "tricks" you can use to help performance:

<%
CONST PAGESIZE = 10 ' or whatever

connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
Server.MapPath("test.mdb")
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open connStr

Set rs = Server.CreateObject("ADODB.Recordset")
rs.MaxRecords = PAGESIZE
rs.CursorLocation = 3 ' client side cursor

RS.open conn,"SELECT * FROM q_anagrafica", 3

rs.PageSize = PAGESIZE
rs.AbsolutePage = pag

For rnum = 1 To PAGESIZE
If RS.EOF Then Exit For
' don't put parens around the argument to response.Write!
' it's actually a minor performance hit
response.write rs("id") & " - " & rs("nome") & "<hr>" & vbNewLine
rs.Movenext
Next
....
%>

Jun 30 '08 #1
10 2142
Thanks a lot... I'll implement this solution right now!

Can you recommend a good book on this themes (I mean ASP - I know
ASP.net is better but for the moment... - and database)?

bye
Paolo

Old Pedant wrote:
I'll make it easy on you...

The culprit is your line
Set rs = conn.Execute ("exec q_anagrafica")

When you open a recordset that way, you *always* get a forward-only cursor
(adForwardOnly) and a read-only recordset (adLockReadOnly).

Which means you can *NOT* then use RS.AbsolutePage or any of its kin.

So, as you said, you expected to use
RS.open conn,"exec q_anagrafica", 3
to get pagination, using the static cursor.

But now the culprit is that fact you are trying to use EXEC here and Access
doesn't really handle EXEC gracefully.

But luckily, an Access STORED QUERY is no different than a TABLE, when
viewed from a SQL query. So you can, instead, just do
RS.open conn,"SELECT * FROM q_anagrafica", 3
and it should all work.

Finally, a couple of "tricks" you can use to help performance:

<%
CONST PAGESIZE = 10 ' or whatever

connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
Server.MapPath("test.mdb")
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open connStr

Set rs = Server.CreateObject("ADODB.Recordset")
rs.MaxRecords = PAGESIZE
rs.CursorLocation = 3 ' client side cursor

RS.open conn,"SELECT * FROM q_anagrafica", 3

rs.PageSize = PAGESIZE
rs.AbsolutePage = pag

For rnum = 1 To PAGESIZE
If RS.EOF Then Exit For
' don't put parens around the argument to response.Write!
' it's actually a minor performance hit
response.write rs("id") & " - " & rs("nome") & "<hr>" & vbNewLine
rs.Movenext
Next
...
%>
Jul 1 '08 #2
Sorry, just the last question:

what about if I have to pass a parameter to the query?
I mean something like "q_anagrafica 2008" to have just the 2008 employees?

How change the

RS.open conn,"SELECT * FROM q_anagrafica", 3

script?

thanks

Old Pedant wrote:
I'll make it easy on you...

The culprit is your line
Set rs = conn.Execute ("exec q_anagrafica")

When you open a recordset that way, you *always* get a forward-only cursor
(adForwardOnly) and a read-only recordset (adLockReadOnly).

Which means you can *NOT* then use RS.AbsolutePage or any of its kin.

So, as you said, you expected to use
RS.open conn,"exec q_anagrafica", 3
to get pagination, using the static cursor.

But now the culprit is that fact you are trying to use EXEC here and Access
doesn't really handle EXEC gracefully.

But luckily, an Access STORED QUERY is no different than a TABLE, when
viewed from a SQL query. So you can, instead, just do
RS.open conn,"SELECT * FROM q_anagrafica", 3
and it should all work.

Finally, a couple of "tricks" you can use to help performance:

<%
CONST PAGESIZE = 10 ' or whatever

connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
Server.MapPath("test.mdb")
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open connStr

Set rs = Server.CreateObject("ADODB.Recordset")
rs.MaxRecords = PAGESIZE
rs.CursorLocation = 3 ' client side cursor

RS.open conn,"SELECT * FROM q_anagrafica", 3

rs.PageSize = PAGESIZE
rs.AbsolutePage = pag

For rnum = 1 To PAGESIZE
If RS.EOF Then Exit For
' don't put parens around the argument to response.Write!
' it's actually a minor performance hit
response.write rs("id") & " - " & rs("nome") & "<hr>" & vbNewLine
rs.Movenext
Next
...
%>
Jul 1 '08 #3
I would do it like this:

set rs=createobject("adodb.recordset")
rs.cursortype=3
conn.q_anagrafica 2008,rs

Trust me, this works. You can also use this technique to execute an action
query that does not return records, just leave off the recordset argument:

conn.q_action 2008

Paolo Galli wrote:
Sorry, just the last question:

what about if I have to pass a parameter to the query?
I mean something like "q_anagrafica 2008" to have just the 2008
employees?
How change the

RS.open conn,"SELECT * FROM q_anagrafica", 3

script?

thanks

Old Pedant wrote:
>I'll make it easy on you...

The culprit is your line
Set rs = conn.Execute ("exec q_anagrafica")

When you open a recordset that way, you *always* get a forward-only
cursor (adForwardOnly) and a read-only recordset (adLockReadOnly).

Which means you can *NOT* then use RS.AbsolutePage or any of its kin.

So, as you said, you expected to use
RS.open conn,"exec q_anagrafica", 3
to get pagination, using the static cursor.

But now the culprit is that fact you are trying to use EXEC here and
Access doesn't really handle EXEC gracefully.

But luckily, an Access STORED QUERY is no different than a TABLE,
when viewed from a SQL query. So you can, instead, just do
RS.open conn,"SELECT * FROM q_anagrafica", 3
and it should all work.

Finally, a couple of "tricks" you can use to help performance:

<%
CONST PAGESIZE = 10 ' or whatever

connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
Server.MapPath("test.mdb")
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open connStr

Set rs = Server.CreateObject("ADODB.Recordset")
rs.MaxRecords = PAGESIZE
rs.CursorLocation = 3 ' client side cursor

RS.open conn,"SELECT * FROM q_anagrafica", 3

rs.PageSize = PAGESIZE
rs.AbsolutePage = pag

For rnum = 1 To PAGESIZE
If RS.EOF Then Exit For
' don't put parens around the argument to response.Write!
' it's actually a minor performance hit
response.write rs("id") & " - " & rs("nome") & "<hr>" &
vbNewLine rs.Movenext
Next
...
%>
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 1 '08 #4
HUH!!! I never even thought of using an Access stored query like this!

I actually had to go TRY it.

In general, Access queries are too useless to bother with (can't do real
coding...just use conditionals) so I've ignored them except when a single
query gets too complex for the poor little baby. But now you've made me
rethink my use of them.

Fun stuff!

Thanks.

Jul 1 '08 #5
Old Pedant wrote:
HUH!!! I never even thought of using an Access stored query like
this!

I actually had to go TRY it.

In general, Access queries are too useless to bother with (can't do
real coding...just use conditionals) so I've ignored them except when
a single query gets too complex for the poor little baby. But now
you've made me rethink my use of them.

Fun stuff!

Thanks.
And the same technique works with SQL Server stored procedures! :-)

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 1 '08 #6
Oh, sure...and with MySQL.

I just meant I hadn't thought of using it with Access queries because they
aren't "true" stored procedures.

But I guess the presence of a parameter is enough to trigger ADO to doing
the right thing.

I even tried a query where I did
SELECT ... FROM table WHERE id = @id OR parentid = @id
and I only needed to pass a single value. Which of course I would have
*expected* with SQL Server. Just didn't think poor little Access would do it
right. But of course it's not REALLY Access doing it; it's the JET engine.
So I guess that's understandable. Fun.

Jul 1 '08 #7
Old Pedant wrote:
Oh, sure...and with MySQL.

I just meant I hadn't thought of using it with Access queries because
they aren't "true" stored procedures.
Well ... if you look at them with ADOX, guess what collection they are in?
:-)
Actually, a saved query that returns records but does not accept parameters
is contained in the Views collection.

And there are advantages to using them besides the ease of use: they are
parsed and compiled so Jet doesn't have to come up with an execution plan
every time they are run ...

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 1 '08 #8
Well ... if you look at them with ADOX, guess what collection they are in?
:-)
LOL! Never thought of looking at them ADOX. Not surprising, given that I
didn't use them for the other reasons mentioned.
And there are advantages to using them besides the ease of use: they are
parsed and compiled so Jet doesn't have to come up with an execution plan
every time they are run ...
And not to mention that you can use queries and subqueries and thus build up
SQL that will actually run in Access/JET but that can't run if you try to do
it all as a single ad hoc query. Can't tell you how many times I've gotten
"expression too complex" and fixed it within minutes by using stored queries.

So... You've just given me more reason to use them.

Of course, now that I learn all these tricks, my days of using Access with
ASP are numbered. The only use I make of that combination nowadays is on a
couple of ".org" sites I helped set up for some non-profits. And even those,
if I ever get around to recoding them, I'll likely move to SQL Server, just
because. I moved them all to use GoDaddy's cheapest hosting plan, and even
at $4 a month they give you one 200MB SQL Server DB, which is overkill for
all these little sites.

Anyway...too bad I didn't know some of this stuff 7 and 8 years ago. (Of
course, back then I don't think this stuff worked, did it? When did the
ability to call sp's by name from connection object arrive on the scene? ADO
2.5? 2.6? Hmmm...could n't find it. Found docs for 2.1 and clearly wasn't
there at that time.)
Jul 2 '08 #9
Old Pedant wrote:
Anyway...too bad I didn't know some of this stuff 7 and 8 years ago.
(Of course, back then I don't think this stuff worked, did it? When
did the ability to call sp's by name from connection object arrive on
the scene? ADO
2.5? 2.6? Hmmm...could n't find it. Found docs for 2.1 and clearly
wasn't there at that time.)
I believe 2.5 introduced it. And, my memory is a little foggy on this, but I
believe it did not work with Jet until the 4.0 provider was released, since
that was the first provider to expose the saved queries as procedures.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 2 '08 #10
Bob Barrows [MVP] wrote:
Old Pedant wrote:
>Anyway...too bad I didn't know some of this stuff 7 and 8 years ago.
(Of course, back then I don't think this stuff worked, did it? When
did the ability to call sp's by name from connection object arrive on
the scene? ADO
2.5? 2.6? Hmmm...could n't find it. Found docs for 2.1 and clearly
wasn't there at that time.)

I believe 2.5 introduced it. And, my memory is a little foggy on
this, but I believe it did not work with Jet until the 4.0 provider
was released, since that was the first provider to expose the saved
queries as procedures.
Hmm, Jet 4.0 was released with MDAC 2.1, so i would be surprised it the
procedure-as-connection-method techniques was not possible with 2.1. I don't
have the docs for that version, but you would find it if it's there in the
overview of the connection object.
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 2 '08 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Max | last post by:
Is it possible or more effecient to use a stored procedure to populate a datagrid when using datagrid or custom paging? Is it (ADO.NET?) pulling the entire table into the dataset or is it just...
1
by: Guoqi Zheng | last post by:
Sir, The default paging of datagrid is somehow use too much resource, so I am using Stored procedure for the paging. You can find my Stored procedure at the end of this message. It works...
6
by: Shawn | last post by:
Hi. I already have a datagrid where I'm using paging. I have a stored procedure that fills a temp table with 200-500 rows and then sends back 10 records at the time. When I go to page 2 the SP...
2
by: asad | last post by:
Hello friends, i am designing a ASP.NET page where i want to use custom paging bcoz data is too heavy so pls tell me how can i use custom paging in ASP.NET Thanks
1
by: Islamegy® | last post by:
I don't know why All my stored Procedure which provide custom pageing don't work in .Net 2.. First i was using Procedures genrated by CodeSmith and N-Tier.. which create #temp table with auto...
0
by: anonieko | last post by:
This approach I found very efficient and FAST when compared to the rowcount, or Subquery Approaches. This is before the advent of a ranking function from DB such as ROW_NUMBER() in SQL Server...
7
by: =?Utf-8?B?SmVmZiBCZWVt?= | last post by:
The default paging behavior of the gridview doesn't work well with very large sets of data which means we have to implement some sort of custom paging. The examples I have seen (4guysfromrolla,...
2
by: Ilyas | last post by:
Hi all I need to implmenet paging across different tables. The tables all have a different name eg Data01, data02 data03 etc, however they are columns which are common to each table, but each...
2
by: Bob Barrows [MVP] | last post by:
Paolo Galli wrote: You should probably read here to see some more efficient techniques (this article does contain the answer to your problem even if you are not interested in using a different...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.