ASP recordset to array

Im using asp and sql server for a web page

I've got a simple recordset:

I want to display the data in a series of select lists based on itemcategory. I could pull a different recordset for each category, but that seems way clunky.

How can I pull one recordset and distribute to the appropriate select lists? The selects should be built dynamically so one category, one select list. 8 (or whatever)categories, 8 select lists.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


Your query should look like this

select itemid, itemname, itemcategory
from tablename
order by itemcategory

Then in your asp page you should do something like this (pseudo code):

while myReader.Read()

  if myReader("itemcategory") <> oldCategory then
    dynamicSelectList = new selectlist()
    dynamicSelectList.Add(myReader("itemname"), myReader("itemid"))
    oldCategory = myReader("itemcategory")
    dynamicSelectList.Add(myReader("itemname"), myReader("itemid"))
  end if


Not sure exactly how you add a select box to a page dynamically using asp, but this should give you an idea of how to deal with it for SQL

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
also, since Classic ASP (as opposed to ASP.NET) uses ADO as the Data Access Technology, after you have an ADO Recordset, you can use the Recordset.GetRows methood to create an Array of n Rows (one row for each record) and m columns (i column for each field in each record) or VARIANTS (so each colum can hold a different KIND of value:

dim cn
Dim rs
Dim strSQL
dim MyArr

set cn = Server.CreateObject("ADODB.Connection")
cn.ConnectionString = ....

set rs = Server.CreateObject(ADODB.Recordset")
strSQL = "select itemid, itemname, itemcategory from tablename order by itemcategory"

rs.OpenRecordset(strSQL, cn)
MyArr = rs.GetRows()

now you can use this array for whatever purposes you need.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.