469,898 Members | 1,713 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

get recordset value outside the table

I need to display data like this:

CompanyName1

Company | Date| Transactions Count -- headers
CompanyName1 | Date| 1 -- data
CompanyName2 | Date| 5 -- data
CompanyName3 | Date| 2 -- data
CompanyName4 | Date| 7 -- data

COMPANYNAME1 should be outside the table
<table>
<tr>
<%
For each fld in objRS.Fields
Response.Write("<td>" & fld.Name & "</td>")
Next
objRS.MoveFirst
%>
</tr>
<%
Do until objRS.EOF
%>
<tr>
<%
For each fld in objRS.Fields
Response.Write("<td>" & fld & "</td>")
Next
objRS.MoveNext
%>
</tr>
</table>

Help please!
Jul 19 '05 #1
9 3799
Hamster wrote:
I need to display data like this:

CompanyName1

Company | Date| Transactions Count -- headers
CompanyName1 | Date| 1 -- data
CompanyName2 | Date| 5 -- data
CompanyName3 | Date| 2 -- data
CompanyName4 | Date| 7 -- data

COMPANYNAME1 should be outside the table
<table>
<tr>
<%
For each fld in objRS.Fields
Response.Write("<td>" & fld.Name & "</td>")
Next
objRS.MoveFirst
%>
</tr>
<%
Do until objRS.EOF
%>
<tr>
<%
For each fld in objRS.Fields
Response.Write("<td>" & fld & "</td>")
Next
objRS.MoveNext
%>
</tr>
</table>

Help please!


Please rephrase your question.

Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #2
I have table with headers and data populated dynamically.

<table border="1" cellpadding="0" cellspacing="0">
<tr>
<%
For each fld in objRS.Fields
Response.Write("<td>" & fld.Name & "</td>")
Next
objRS.MoveFirst
%>
</tr>
<%
Do until objRS.EOF
%>
<tr>
<%
For each fld in objRS.Fields
Response.Write("<td>" & fld & "</td>")
Next
objRS.MoveNext
%>
</tr>
<%
Loop
%>
</table>

What I need:
1)C1 to be the title of the table, it should be outside <table> tag
2)Company column to be hidden (I know the column to be hidden, it's the
one that has ~T~ at the end)

C1

Company | Date | Transaction
C1 12/12/2003 Transaction1
C1 12/13/2003 Transaction2
C1 12/14/2003 Transaction3

Thanks.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #3
Katya Kotova wrote:

What I need:
1)C1 to be the title of the table, it should be outside <table> tag
That's easy enough. It looks like every record in the recordset has "C1" in
the first field. So just read the value of the first field and write it to
the response before starting the table.

2)Company column to be hidden (I know the column to be hidden, it's
the one that has ~T~ at the end)


Sorry, but this means nothing to me. I'm not looking over your shoulder. I
don't know where you are seeing this "~T~".

I'm assuming Company is the first field in the recordset? Why create the
column in the table if you want it to be hidden?
<%
'open the recordset - use rs, not objRS (less typing)
Response.write rs(0)
%>
<table border="1" cellpadding="0" cellspacing="0">
<%
Dim i
response.write "<tr>"
for i = 1 to rs.Fields.count - 1
Response.Write("<td>" & rs.Fields(i).Name & "</td>")
next
response.write "</tr>"
'no need to do a MoveFirst here
Do until rs.EOF
response.write "<tr>"
for i = 1 to rs.Fields.count - 1
Response.Write("<td>" & rs(i) & "</td>")
next
response.write "</tr>"
loop
response.write "</table>"
%>

HTH,
Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #4
Thanks.
I would like to do this for every column that has, for example,
Right(fld.Name, 4) = "name", not only for the first column.

I am creating a universal component that I can use for a lot of web
reports.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #5
Katya Kotova wrote:
Thanks.
I would like to do this for every column that has, for example,
Right(fld.Name, 4) = "name", not only for the first column.

I am creating a universal component that I can use for a lot of web
reports.

Please provide a more detailed example that thoroughly explains what you
mean by "do this".

Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #6
I would like to take first field value from column that has "name" at
the end (it can be 2nd, 3rd, 11th column)and to make this value to be a
title of this table.

Smith & Co

ID | EmployeeID | Contact | CompanyName |
12 | 12345 | Smith | Smith & Co
13 | 12346 | Gardner | Smith & Co

Thanks for your patience.
I am trying to create component that I can use for a number of web
reports. It should determine the column name with "name" at the end, and
if it exists it should create a title from it's first value and hide
this particular column.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #7
Katya Kotova wrote:
I would like to take first field value from column that has "name" at
the end (it can be 2nd, 3rd, 11th column)and to make this value to be
a title of this table.

Smith & Co

ID | EmployeeID | Contact | CompanyName |
12 | 12345 | Smith | Smith & Co
13 | 12346 | Gardner | Smith & Co

Thanks for your patience.
I am trying to create component that I can use for a number of web
reports. It should determine the column name with "name" at the end,
and if it exists it should create a title from it's first value and
hide this particular column.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #8
Katya Kotova wrote:
I would like to take first field value from column that has "name" at
the end (it can be 2nd, 3rd, 11th column)and to make this value to be
a title of this table.

Smith & Co

ID | EmployeeID | Contact | CompanyName |
12 | 12345 | Smith | Smith & Co
13 | 12346 | Gardner | Smith & Co

Thanks for your patience.
I am trying to create component that I can use for a number of web
reports. It should determine the column name with "name" at the end,
and if it exists it should create a title from it's first value and
hide this particular column.


Errm, OK.

I assume you will have some method to make sure that only one field ends
with the word "name" given that you don't know either the names of the
fields or the order in which they will be retrieved ...?

Enough with this inefficient recordset looping. Time to use some arrays:

'open the recordset, then
Dim arData. arNames(), i, j, NameIndex
redim arNames(rs.Fields.Count - 1)
for i = 0 to rs.Fields.Count - 1
if lcase(Right(rs.Fields(i).Name,4)) = "name" then NameIndex = i
arNames(i) = rs.Fields(i).Name
next
if not rs.EOF then arData = rs.GetRows
rs.close: set rs=nothing
'close and destroy the connection as well

'arData will not be an array if no records were returned
If IsArray(arData) then

'write the value contained in the column identified by NameIndex
'from the first row of data in arData
Response.Write arData(NameIndex,0) & "<BR>"

'Build the table using all columns except the one identified by
'NameIndex

Response.Write "<table><tr>"
for i = 0 to ubound(arNames)
if i <> NameIndex then
Response.Write "<th>"
Response.Write arNames(i)
Response.Write "</th>"
End If
next
Response.Write "</tr>"

for i = 0 to Ubound(arData,2)
Response.Write "<tr>"
for j = 0 to Ubound(arData,1)
If j <> NameIndex then
Response.Write "<td>"
Response.Write arData(j,i)
Response.Write "</td>"
End if
next
Response.Write "</tr>"
next
Response.Write "</table>"

Else
'handle the situation where no records were returned
End if

HTH,
Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #9
thanks a lot, Bob


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

22 posts views Thread by Gerry Abbott | last post: by
1 post views Thread by Ray Holtz | last post: by
11 posts views Thread by altreed | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.