Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1180
  • Last Modified:

ASP recordset to array

Im using asp and sql server for a web page

I've got a simple recordset:
itemid
itemname
itemcategory

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.
0
webdork
Asked:
webdork
2 Solutions
 
curlypinheadCommented:
Hello...

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
    page.add(dynamicSelectList)
    dynamicSelectList = new selectlist()
    dynamicSelectList.Add(myReader("itemname"), myReader("itemid"))
    oldCategory = myReader("itemcategory")
  else
    dynamicSelectList.Add(myReader("itemname"), myReader("itemid"))
  end if

next

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
0
 
Arthur_WoodCommented:
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 = ....
cn.OPen()

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.

AW
0

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now