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"