473,322 Members | 1,417 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,322 software developers and data experts.

How do I do this with ADO and an Access DB in ASP 3.0?

How do I return multiple counts for display in an ASP 3.0 page?

For example, I want to display record counts for each state on the page.
Something that looks like this:

CA - 50
NY - 12
SC - 18

Right now I loop through each state (the id for each state), open a record
set, execute a query, print the count, close the recordset and repeat like
this:

Dim cnt
cnt=1
Do while cnt <= 50

ssql="SELECT count(*) FROM states WHERE stateid =" & cnt
With rs
.CursorLocation=3 'adUserClient
.ActiveConnection=cn
.source=sSql
.Open
End With

Response.Write (rs.Fields(0))

cnt=cnt+1
rs.Close
loop

Obviously this not very efficient. Can anyone suggest an improvement?

Remember I am working with Access so I believe I have to return a record set
rather than accessing a singleton like a SQL Server RETURN value.

Any ideas would be appreciated.

Dave



Sep 9 '06 #1
3 1472

Dave wrote:
How do I return multiple counts for display in an ASP 3.0 page?

For example, I want to display record counts for each state on the page.
Something that looks like this:

CA - 50
NY - 12
SC - 18

Right now I loop through each state (the id for each state), open a record
set, execute a query, print the count, close the recordset and repeat like
this:

Dim cnt
cnt=1
Do while cnt <= 50

ssql="SELECT count(*) FROM states WHERE stateid =" & cnt
With rs
.CursorLocation=3 'adUserClient
.ActiveConnection=cn
.source=sSql
.Open
End With

Response.Write (rs.Fields(0))

cnt=cnt+1
rs.Close
loop

Obviously this not very efficient. Can anyone suggest an improvement?

Remember I am working with Access so I believe I have to return a record set
rather than accessing a singleton like a SQL Server RETURN value.
I am assumiong that you have a column with the state name in your
table. I have called it StateName below:

<%
ssql = "SELECT StateName, COUNT(StateName) AS Countofstate FROM States
GROUP BY StateID"

Set rs = cn.execute(ssql)
If not rs.EOF Then
arrCount = rs.Getrows
rs.close : set rs = nothing
For i = 0 to Ubound(arrCount,2)
Response.Write arrCount(0,i) & ": " & arrCount(1,i)
Next
Else
Response.Write "No Records to show"
rs.Close : Set rs = Nothing
End If
%>

The method above grabs all the records in one go, puts them into an
array, and allows you to close and destroy the recordset object
immediately.

Sep 9 '06 #2

"Dave" <da*******@newsgroup.nospamwrote in message
news:ut**************@TK2MSFTNGP03.phx.gbl...
How do I return multiple counts for display in an ASP 3.0 page?

For example, I want to display record counts for each state on the page.
Something that looks like this:

CA - 50
NY - 12
SC - 18

Right now I loop through each state (the id for each state), open a record
set, execute a query, print the count, close the recordset and repeat like
this:

Dim cnt
cnt=1

note that the GROUP BY statement has a syntax. look at google for the
correct syntax if you want to add more information on 'states' for instance.

ssql="SELECT count(stateid) FROM states GROUP BY stateid"
With rs
.CursorLocation=3 'adUserClient
.ActiveConnection=cn
.source=sSql
.Open
End With

Response.Write (rs.Fields(0))

cnt=cnt+1
rs.Close
>
Obviously this not very efficient. Can anyone suggest an improvement?

Remember I am working with Access so I believe I have to return a record
set rather than accessing a singleton like a SQL Server RETURN value.

Any ideas would be appreciated.

Dave


Sep 9 '06 #3
Thanks guys!
"Egbert Nierop (MVP for IIS)" <eg***********@nospam.invalidwrote in
message news:%2****************@TK2MSFTNGP05.phx.gbl...
>
"Dave" <da*******@newsgroup.nospamwrote in message
news:ut**************@TK2MSFTNGP03.phx.gbl...
>How do I return multiple counts for display in an ASP 3.0 page?

For example, I want to display record counts for each state on the page.
Something that looks like this:

CA - 50
NY - 12
SC - 18

Right now I loop through each state (the id for each state), open a
record set, execute a query, print the count, close the recordset and
repeat like this:

Dim cnt
cnt=1


note that the GROUP BY statement has a syntax. look at google for the
correct syntax if you want to add more information on 'states' for
instance.

ssql="SELECT count(stateid) FROM states GROUP BY stateid"
With rs
.CursorLocation=3 'adUserClient
.ActiveConnection=cn
.source=sSql
.Open
End With

Response.Write (rs.Fields(0))

cnt=cnt+1
rs.Close
>>
Obviously this not very efficient. Can anyone suggest an improvement?

Remember I am working with Access so I believe I have to return a record
set rather than accessing a singleton like a SQL Server RETURN value.

Any ideas would be appreciated.

Dave



Sep 10 '06 #4

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

Similar topics

63
by: Jerome | last post by:
Hi, I'm a bit confused ... when would I rather write an database application using MS Access and Visual Basic and when (and why) would I rather write it using Visual Studio .Net? Is it as easy...
14
by: wolftor | last post by:
1) Is there a free runtime version of Access available that is more recent than the one for Access 2000? 2) If I create an application (MDE) in A2K, will it run on all later versions of Access?...
3
by: Scott | last post by:
Hi, If we want to compile an Access 2002 database and distribute it to others, will the compiled software run on any PC, like Windows 98, Windows 2000, etc. Also, you don't have to have...
5
by: Praty77 | last post by:
Hello - we have been using access 97 for a multiple user trading system at a small bank. Typically around 10 users entered a total of hundred trades everyday. Some of the data was shared with a...
20
by: Olav.NET | last post by:
I am a .NET/C++ developer who is supposed to do some work with Access. I do not know much about it except for the DB part. Questions: *1* I am looking for INTENSIVE books to get quickly up to...
4
by: ljubo lecic via AccessMonster.com | last post by:
I am an experienced ORACLE software developer who met ACCESS few months ago and I must say that ,so far, I am delighted. I rapidly developed a few aplications and everything is working extremly...
3
by: KEMDignam | last post by:
I have upgraded my computer to Access 2003, but I have not converted my databases since all of my clients still use Access 2000. I need to create a new MDB, but Access is telling me that I will...
92
by: Jeffrey P via AccessMonster.com | last post by:
Our IT guys are on a vendetta against MS Access (and Lotus Notes but they've won that fight). What I can't understand is, what's the problem? Why does IT hate MS Access so much. I have tried...
2
by: Dean Slindee | last post by:
Anybody written code in VB.NET to: 1) show a print preview window of reports already written and stored in an Access 2002 database; or 2) execute the print of a report stored in an Access 2002...
22
by: Jordan S. | last post by:
SQL Server will be used as the back-end database to a non trivial client application. In question is the choice of client application: I need to be able to speak intelligently about when one...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.