ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old August 24th, 2003, 09:49 PM
abones abones is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 75 abones User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Question ASP Paging (MS SQL)

I have some problems connecting to to my Microsoft SQL Server 2000. I'm doing ADO Paging to separate results into several pages. I've got the code below from google and was trying to modify it to suit my program. When i do a check for

Response.write rs.Pagesize
or
Response.write rs.Count

it will return -1

I have around 200records, so it should return me a value.
==============================================


Sql = "SELECT IDX, CLIENTIDX, COMPANY FROM CL_ADDRESSES WHERE CLIENTIDX= '" & Session.Contents("clientidx") & "' ORDER BY COMPANY"

rs.CursorLocation = 3
rs.CursorType = 3

rs.ActiveConnection = Session("Conn")
set rs = Session("Conn").Execute(Sql)

rs.PageSize = 20
rs.CacheSize = rs.PageSize
intPageCount = rs.PageCount
intRecordCount = rs.RecordCount

If CInt(intPage) > CInt(intPageCount) Then intPage = intPageCount
If CInt(intPage) <= 0 Then intPage = 1

If intRecordCount > 0 Then
rs.AbsolutePage = intPage
intStart = rs.AbsolutePosition
If CInt(intPage) = CInt(intPageCount) Then
intFinish = intRecordCount
Else
intFinish = intStart + (rs.PageSize - 1)
End if
End If

If RS.EOF Then
RS.Close
Response.Write "No Items found."
ELSE
...
....
End if

==============================================
I had placed the connection portion in global.asa on the Session_onstart event.
Could anyone advise me on this? Thanks in advance

Reply With Quote
  #2  
Old August 24th, 2003, 10:27 PM
unatratnag unatratnag is offline
Average Intelligence
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2003
Location: Ohio/Chicago
Posts: 678 unatratnag User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 22 sec
Reputation Power: 6
Send a message via AIM to unatratnag
a) have you tested the statement in the DBMS?
b) have you printed out Session.Contents("clientidx") to see what it's value is before hand?
c) have you printed out the SQL string generated by your asp coding to make sure you didn't screw anything up in the switch over?
d) are you sure you're using the method for the record set correctly?
e) this sounds like asp.net, have you tried that forum instead of the just plain pure asp forum?

Reply With Quote
  #3  
Old August 24th, 2003, 11:01 PM
abones abones is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 75 abones User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
It did retrieve the Session.Contents("Clientidx").
I tested the the statement and Query Analyzer and it worked.
The above code return 20 records to the page only but when i do a check for AbsolutePage, PageCount, it will still return -1

Reply With Quote
  #4  
Old August 25th, 2003, 02:29 AM
Doug G Doug G is online now
Grumpier Old Moderator
Dev Shed God 12th Plane (10500 - 10999 posts)
 
Join Date: Jun 2003
Posts: 10,717 Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 1 Month 40 m 34 sec
Reputation Power: 688
You can open recordsets in ways that will not provide you with a recordcount. One problem when you execute sql on your connection, you will get a forward-only read-only recordset, which doesn't happen to support recordcount.

Instead of the con.execute(sql), try something like:
Code:
set rs = server.createobject("ADODB.Recordset")
rs.CursorType = 3
rs.CursorLocation = 3
set rs.ActiveConnection = Session("conn")  '<--I wouldn't ever put an ado object in a session variable :(
rs.open sql


Take a look at the documentation for the recordset.recordcount property, there is a description of various conditions that prevent getting a recordcount from your ado recordset, and some comments on possible performance issues when using recordcount.

You can always roll your own recordcount with a SELECT COUNT(*) FROM table

Reply With Quote
  #5  
Old August 26th, 2003, 09:42 PM
abones abones is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 75 abones User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Do you mean it's better to open the connection on each page that needs it, then close the connection as soon as you are finished with it?

What's the use of Global.asa anyway?
Do we store connection there?

==============================================
Where i stored my db connection ..
==============================================
<script language="vbscript" runat="server">
sub Application_OnStart
end sub

sub Application_OnEnd
end sub

sub Session_OnStart
'' Now i'm placing all my db connection here
Set Session("Conn") = Server.CreateObject("ADODB.Connection")
Session("Conn").Provider = "SQLOLEDB"
Session("Conn").Open("server=192.168.0.22;UID=sa;PWD=test;database=test;")
end sub

sub Session_OnEnd
Session.Abandon
end sub
</script>
=============================================

Can i say that my approach is wrong?

Reply With Quote
  #6  
Old August 27th, 2003, 02:08 AM
Doug G Doug G is online now
Grumpier Old Moderator
Dev Shed God 12th Plane (10500 - 10999 posts)
 
Join Date: Jun 2003
Posts: 10,717 Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 1 Month 40 m 34 sec
Reputation Power: 688
Quote:
Do you mean it's better to open the connection on each page that needs it, then close the connection as soon as you are finished with it?

Yes.

http://msdn.microsoft.com/library/d...tml/ASPtips.asp

If you look in the msdn library at http://msdn.microsoft.com/library there is full documentation on global.asa

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > ASP Paging (MS SQL)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway