Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GetRows question

Status
Not open for further replies.

Chopstik

Technical User
Oct 24, 2001
2,180
US
I am learning about GetRows at the moment, thinking it might help speed up one of my applications. I did one thing on a single column within a database table and it came back with the information just like I wanted. However, when I added another column to the first from that same database, it produces my data in a single column down the page, for example:

Ronald Reagan
40
Jimmy Carter
39
Gerald Ford
38

Is there a way to produce the information in a table format, perhaps? Thanks.
 
<tr>
<td>
item
</td>
<td>
item
</td>
</tr>
looks like this:
item item
<tr>
<td>
item
</td>
</tr>
<tr>
<td>
item
</td>
</tr>
looks like this:
item
item
In between a tr tag you put a line and in between td you put the column items.
 
Thanks, Harmmeijer, that was what I finally ended up having to do. I guess that should have been an easy one, but I prefer looking for the hard way first. :)
 
I have a couple of routines that might be of use to you. The first is called transpose. This uses the getrows function to create an array out of GetRows, converting rows to columns and columns to rows. Its useful if you want to paste the data into Excel.

function TransposeRS(oRS, IncHdr)
‘//////////////////////////////////// this routine converts recordsets to arrays for easy insert into OWC
dim lCurrField
dim lCurrRow
dim lFieldCount
dim lRowCount
dim tempArray()
dim vArray
‘------------------------ convert recordset to array
oRS.MoveFirst
vArray = oRS.GetRows
‘------------------------ get size
lRowCount = UBound(vArray, 2)
lFieldCount = UBound(vArray, 1)
ReDim tempArray(lRowCount + IncHdr, lFieldCount - 0)
‘------------------------ include field names if needed
if IncHdr = 1 then
For lCurrField = 0 To lFieldCount
tempArray(0, lCurrField) = oRS.Fields(lCurrField).Name
Next
end if
‘------------------------ transpose from fields in rows to fields in columns
For lCurrRow = 0 To lRowCount
For lCurrField = 0 To lFieldCount
tempArray(lCurrRow + IncHdr, lCurrField) = vArray(lCurrField, lCurrRow)
Next
Next
TransposeRS = tempArray
end function

The second routine just prints a table from a recordset. It seems that is what you want to do. Basically, I open up the recordset in the main asp code, then call the routine. If I want to see the headers more than once, I set the LineToBreak parameter to a value of about 25, else I make it 1000.

Its a down and dirty routine, but its fast. When you want to create a format, its easy to customize the style.

sub PrintRecordList(LinesToBreak)
dim i, nFld, j, cnt
nFld = oRS.fields.count - 1
Response.Write &quot;<table cellspacing=1 cellpadding=1 border=1 WIDTH=800px><tr>&quot;
for i = 0 to nFld
Response.Write &quot;<td align=left><font face=arial size=2><strong>&quot; & oRS.fields(i).name & &quot;</strong></td></font>&quot;
next
Response.Write &quot;</tr>&quot;

while not(oRS.EOF) and (nFld > 0)
cnt = cnt + 1
Response.Write &quot;<tr>&quot;
for i = 0 to nFLd
if isnull(oRS.fields(i).value) then
Response.Write &quot;<td align=left><font face=arial size=1>&nbsp;</td></font>&quot;
else
if len(oRS.fields(i).value) = 0 then
Response.Write &quot;<td align=left><font face=arial size=2>&nbsp;</td></font>&quot;
else
Response.Write &quot;<td align=left><font face=arial size=2>&quot; & oRS.fields(i).value & &quot;</td></font>&quot;
end if
end if
next
Response.Write &quot;</tr>&quot;
oRS.MoveNext
if cnt mod LinesToBreak = 0 and not(oRS.eof) then
Response.Write &quot;</table><P>&quot;
response.flush
Response.Write &quot;<table cellspacing=1 cellpadding=1 border=1 WIDTH=800px><tr>&quot;
for i = 0 to nFld
Response.Write &quot;<td align=left><font face=arial size=2><strong>&quot; & oRS.fields(i).name & &quot;</strong></td></font>&quot;
next
Response.Write &quot;</tr>&quot;
end if
wend
Response.Write &quot;</table><P>&nbsp;&nbsp;&nbsp;&quot; & cnt & &quot; record(s) found&quot;
end sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top