Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Sorting after using the GetRows method


Message #1 by "Steve Burr" <steveb1164@a...> on Fri, 25 May 2001 08:36:04
The GetRows method of putting a recordset into an array puts the columns 

where the rows should be and vice-versa.  I need to sort by one of the 

columns in the recordset, but in the array, that would mean sorting by one 

of the rows.  I've found a couple of programs that will sort by a column, 

but none that will sort by a row.  So, I need to find out how to either 

reverse the columns and rows in my array, or find a program that sorts by 

rows.  I'm using VBScript with ASP.  I can't use the recordset itself, 

because it takes too much time and I keep getting errors from the server 

that 2 people are trying to update the same table at the same time.  This 

is because when I used the recordset, I would loop through the recordset 4 

times, updating one of the columns and sorting by that column.  Thanks for 

any help you can give.
Message #2 by "Dallas Martin" <dmartin@z...> on Fri, 25 May 2001 11:19:56 -0400
Steve,



First, place a lock on the table for the duration of the select.

Next, order your column in the Select statement: SELECT fld1 FROM table1

ORDER BY fld1 (ASC or DESC).



Declare field constants:

dim fld_order_id, fld_order_item, fld_order_amount, etc:



Use these constants to refer to the values in the array return from GetRow()

The field constant should mirror the order of the selected fields in your

select statement.



      0                     1

2.........................

select order_id, order_item, order_amount ................



fld_order_id = 0

fld_order_item = 1

fld_order_amount = 2



' get number of records in array: first record is at 0 index

RecCount = ubound(arrData,2)



orderID = arrData(fld_order_id,0) ' first record

orderItem  = arrData(fld_order_item,0)

orderAmount = arrData(fld_order_amount,0)



orderID = arrData(fld_order_id,1) ' second record

orderItem  = arrData(fld_order_item,1)

orderAmount = arrData(fld_order_amount,1)



This should make it easier to handle your data



Additionally, you can ORDER multiple columns in the SELECT statement in

different directions.



SELECT fld1,fld2,fld3 FROM table1 ORDER BY fld1 ASC, fld2 DESC, fld3 DESC

SELECT fld1,fld2,fld3 FROM table1 ORDER BY fld1 DESC, fld2 ASC, fld3 ASC





Dallas







----- Original Message -----

From: "Steve Burr" <steveb1164@a...>

To: "ASP Databases" <asp_databases@p...>

Sent: Friday, May 25, 2001 8:36 AM

Subject: [asp_databases] Sorting after using the GetRows method





> The GetRows method of putting a recordset into an array puts the columns

> where the rows should be and vice-versa.  I need to sort by one of the

> columns in the recordset, but in the array, that would mean sorting by one

> of the rows.  I've found a couple of programs that will sort by a column,

> but none that will sort by a row.  So, I need to find out how to either

> reverse the columns and rows in my array, or find a program that sorts by

> rows.  I'm using VBScript with ASP.  I can't use the recordset itself,

> because it takes too much time and I keep getting errors from the server

> that 2 people are trying to update the same table at the same time.  This

> is because when I used the recordset, I would loop through the recordset 4

> times, updating one of the columns and sorting by that column.  Thanks for

> any help you can give.


  Return to Index