rs.Skipfirst??

B

Bryan Harrington

Ok.. so I'm using a .CLASSIC Sub that basically returns a datagrid that is
sortable and does paging. It's very handy since it's fairly generic in that
I can pass it a SQL query and it populates the datagrid using the database
field names as column headings.

So.. my problem, I need the ID of record so I can pass it on the QS to an
edit page, but I don't want to display it as the first column.

Below is the snippet of code, and it does a for each field in RS.Fields...
how do I say skip the first item in the collection?

Thanks!

'display from the current record to the pagesize
for i = intCurrentRecord to RS.PageSize
if not RS.eof then
Response.Write "<tr>" & vbcrlf

'for each field in the recordset
for each field in RS.Fields
Response.Write "<td>" & vbcrlf

'if this field is the "linked field" provide a link
if lcase(strLinkedColumnName) = lcase(field.name) then
Response.Write "<a href=" & strLink & rs("id") & ">" & field.value &
"</a>" & vbcrlf
else
Response.Write field.value
end if
Response.Write "<td>" & vbcrlf
next
Response.Write "<tr>" & vbcrlf
RS.MoveNext
end if
next
 
M

middletree

You could do rs.movenext once, outside of your loop, before you start
displaying anything
 
R

Ray at

i = 0
for each field in RS.Fields
If i > 0 Then
Response.Write "<td>" & vbcrlf

'if this field is the "linked field" provide a link
if lcase(strLinkedColumnName) = lcase(field.name) then
Response.Write "<a href=" & strLink & rs("id") & ">" & field.value &
"</a>" & vbcrlf
else
Response.Write field.value
end if
Response.Write "<td>" & vbcrlf
i = i + 1
next


Have you looked into the getstring or getrows methods? I personally would
use getstring for this (or perhaps getrows when you factor in that you want
to skip writing the first column). But, this will not give you the column
names. But, if you're writing your queries efficiently by naming the
columns, you'll already know their names, right?

Ray at work
 
P

Phillip Windell

Bryan Harrington said:
Below is the snippet of code, and it does a for each field in RS.Fields...
how do I say skip the first item in the collection?
 
B

Bob Barrows

Bryan said:
Ok.. so I'm using a .CLASSIC Sub that basically returns a datagrid
that is sortable and does paging. It's very handy since it's fairly
generic in that I can pass it a SQL query and it populates the
datagrid using the database field names as column headings.

So.. my problem, I need the ID of record so I can pass it on the QS
to an edit page, but I don't want to display it as the first column.

Below is the snippet of code, and it does a for each field in
RS.Fields... how do I say skip the first item in the collection?

Thanks!

'display from the current record to the pagesize
for i = intCurrentRecord to RS.PageSize
if not RS.eof then
Response.Write "<tr>" & vbcrlf

'for each field in the recordset
for each field in RS.Fields
Response.Write "<td>" & vbcrlf

'if this field is the "linked field" provide a link
if lcase(strLinkedColumnName) = lcase(field.name) then
Response.Write "<a href=" & strLink & rs("id") & ">" & field.value
& "</a>" & vbcrlf
else
Response.Write field.value
end if
Response.Write "<td>" & vbcrlf
next
Response.Write "<tr>" & vbcrlf
RS.MoveNext
end if
next

Two choices:

for each field in RS.Fields
If field.name <> "ID" ' or whatever the name of it is
'do the write
end if
next

or

for iCol = 1 to RS.Fields.count - 1
set field=RS.Fields(iCol)
'etc.
next

HTH,
Bob Barrows
PS. You should not use the word "field" as a variable name - avoid names of
intrinsic objects when naming your variables - I usually use "fld"
 
P

Phillip Windell

I wasn't sure if you wanted to skip the first field or to put the first
field in the second column of the display (not the same thing). My other
post if for the display.

If you want to skip the first actual field, then you can use a couter in a
loop instead of a "For Each.." loop. If you use the counter also as the
field index, you can control which field it starts and stops with by what
you have the couter begin with and end with.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,145
Messages
2,570,826
Members
47,372
Latest member
LucretiaFo

Latest Threads

Top