In this scenario there are different ways to approach this, personally I've always found using Arrays a lot easier more flexible and more efficient than using the ADODB.Recordset
.
Once you have a ADODB.Recordset
object regardless of the approach (be it ADODB.Command
, Recordset.Open()
or Connection.Execute()
) you can convert it to a two dimensional array using Recordset.GetRows()
.
Using your example I would structure your code like this;
Please take into consideration this is untested and coded from memory, I just wanted to give you the general gist of how to do this kind of computation in a Classic ASP environment.
Dim rs, data, row, rows
Dim weekno
Dim total_weekno, current_weekno
'Assuming you have instantiated your rs object
'...
'Convert to an Array variable (data)
If Not rs.EOF Then data = rs.GetRows()
'Close and release Recordset from memory
Call rs.Close()
Set rs = Nothing
If IsArray(data) Then
rows = UBound(data, 2)
'Iterate through the array
For row = 0 To rows
'Assuming weekno column is the first in your resultant columns.
weekno = data(0, row)
If weekno = current_weekno Then
'Increment our total for the current weekno by 1.
total_weekno = total_weekno + 1
Else
'Place logic for adding new row to PDF here.
'Use total_weekno to display the incremented total.
'Afterward reset total_weekno for the new current weekno.
total_weekno = 0
'Our weekno has changed so set current weekno.
current_weekno = weekno
End If
Next
End If