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

Recordset Grouping

I am stumped as to how to do what appears to be a very simple thing.
Want to display the results of a query containing fields ID and Item,
grouped by the ID. I only want 1 instance of the ID to appear on the
page as a header for each group. There are 10 IDs in the query
results. Thought I could use <% Response.Write (rsName("Item")) WHERE
ID=1 %>, but doesn't work. How else could I accomplish this? Thanks
for any help--I only have very basic ASP knowledge.

Jul 7 '06 #1
6 1352

<ms****@soon.comwrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
>I am stumped as to how to do what appears to be a very simple thing.
Want to display the results of a query containing fields ID and Item,
grouped by the ID. I only want 1 instance of the ID to appear on the
page as a header for each group. There are 10 IDs in the query
results. Thought I could use <% Response.Write (rsName("Item")) WHERE
ID=1 %>, but doesn't work. How else could I accomplish this? Thanks
for any help--I only have very basic ASP knowledge.
sql = "SELECT item FROM yourTable WHERE id = 1"

rsName.open sql, cnName

do until rsName.EOF

Response.Write (rsName("Item"))
rsName.MoveNext

loop
Jul 7 '06 #2
ms****@soon.com wrote:
I am stumped as to how to do what appears to be a very simple thing.
Want to display the results of a query containing fields ID and Item,
grouped by the ID. I only want 1 instance of the ID to appear on the
page as a header for each group. There are 10 IDs in the query
results. Thought I could use <% Response.Write (rsName("Item"))
WHERE ID=1 %>, but doesn't work. How else could I accomplish this?
Thanks for any help--I only have very basic ASP knowledge.
dim cn,rs,ar,id, sql, i
set cn=createobject("adodb.connection")
cn.open ...
set rs=cn.execute("select distinct id from yourtable",, 1)
if not rs.eof then ar=rs.getrows
rs.close
if isarray(ar) then
set rs=createobject("adodb.recordset")
rs.cursorlocation=3 'adUseClient
sql="select ID, Item from yourtable"
rs.open sql,cn,,,1
set rs.activeconection=nothing
cn.close:set cn=nothing
for i = 0 to ubound(ar,2)
id = ar(0,i)
response.write id
rs.filter = "ID=" & id
do until rs.eof
response.write "<div style=""margin-left:10"">"
response.write rs(1) & "</div>"
loop
next
rs.close: set rs=nothing
else
response.write "No data was returned"
end if

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 7 '06 #3
Darn! I left out the rs.movenext!!

Bob Barrows [MVP] wrote:
do until rs.eof
response.write "<div style=""margin-left:10"">"
response.write rs(1) & "</div>"
rs.movenext
loop
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 7 '06 #4
Bob Barrows [MVP] wrote:
Darn! I left out the rs.movenext!!

Thanks for the reply, but I must be missing something - I keep getting
the error "Arguments are of the wrong type, are out of acceptable
range, or are in conflict with one another". Here's the code I was
using:

<%
dim cn,rs,ar,id, sql, i
set cn=createobject("adodb.connection")
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=database.mdb"
cn.open
set rs=cn.execute("select distinct CatID FROM Test",, 1)

if not rs.eof then ar=rs.getrows
rs.close
if isarray(ar) then
set rs=createobject("adodb.recordset")
rs.cursorlocation=3 'adUseClient
sql="select CatID, Equip from Test"
rs.open sql,cn,,,1
set rs.activeconnection=nothing
cn.close:set cn=nothing
for i = 0 to ubound(ar,2)
id = ar(0,i)
response.write id
rs.filter = "CatID=" & catid
do until rs.eof
response.write "<div style=""margin-left:10"">"
response.write rs(1) & "</div>"
rs.movenext
loop
next
else
response.write "No data was returned"
end if%>

Just so I'm clear--is this supposed to loop thru each of my 10 CatIDs
and display the Equip under each CatID on the same page? Or will this
only give me a single CatID's Equip records? I'm not sure if I was
clear on what I wanted--I need everything on the same page. Thanks
again, and apologies if I'm missing something.

Jul 10 '06 #5
Slim wrote:
>
sql = "SELECT item FROM yourTable WHERE id = 1"

rsName.open sql, cnName

do until rsName.EOF

Response.Write (rsName("Item"))
rsName.MoveNext

loop
Thanks for the reply, but if I set the where clause in the query, I'm
going to have to have 10 queries on my page (one for each ID--which is
what I'm doing now) in order to display all the items under each ID. I
had hoped for a better way to do this, since it doesn't seem like I
should have to run all those queries just to group records by the ID #.
But maybe I'm wrong and running all those queries is the only way I
can do this?!?

Jul 10 '06 #6
ms****@soon.com wrote:
Bob Barrows [MVP] wrote:
>Darn! I left out the rs.movenext!!


Thanks for the reply, but I must be missing something - I keep getting
the error "Arguments are of the wrong type, are out of acceptable
range, or are in conflict with one another".
Never tell us an error message without telling us which line generated
the error
Here's the code I was
using:

<%
dim cn,rs,ar,id, sql, i
set cn=createobject("adodb.connection")
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=database.mdb"
I see that this connection string is on two lines. It should be a single
line. In fact, replace it with this:

cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=database.mdb"

If that's not the problem, then you need to tell me which line causes
the error. I obviously cannot debug this myself.
>
Just so I'm clear--is this supposed to loop thru each of my 10 CatIDs
and display the Equip under each CatID on the same page?
Yes

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 10 '06 #7

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

Similar topics

8
by: mgm | last post by:
hello, I have a query that is supposed to return only 1 record, however I recently found that because of an error in the database it can return more than 1. So what I need to do is capture if it...
1
by: amber | last post by:
Hello, I have a report in VB.NET/Crystal Reports. I have a criteria form that users select between 2 different types of grouping (group by category or group by year). Can I programmatically...
2
by: Andreas Håkansson | last post by:
Seeing how my previous post seem to have fallen between the cracks, I thought I would have a second, more direct, go at it. So my question is "Is it possible to group (Muenchian method) over...
22
by: Gerry Abbott | last post by:
Hi all, I having some confusing effects with recordsets in a recent project. I created several recordsets, each set with the same number of records, and related with an index value. I create...
3
by: ahaque38 | last post by:
Hello. Using A2K SP3, I am having the following problem with a report using "Sorting and Grouping". I have recently added a grouping in the reports for "Category2<>'CONTRACTS'". I have...
8
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At...
1
by: WStoreyII | last post by:
I am trying to make a finances database. I have a master table which contains transaction header info and then a line details table. What i want is to make a reconcile query where i can see...
0
by: Roman Bertle | last post by:
Hello, I try to format monetary values using the locale module, python2.5: Python 2.5.2a0 (r251:54863, Jan 3 2008, 17:59:56) on linux2 Type "help", "copyright", "credits" or "license" for...
3
by: Gord | last post by:
Me again, I'm new to Access and am self teaching from a couple of books, so bear with me. (I've got a little experience with Visual Basic) As I understand so far, if I want to perform a bunch...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.