motorpilot
asked on
ASP recordset string concatenation
Hi,
I am trying to reduce my asp coding by creating a loop that retrieves data from my SQL database. The database column entries are named column1, column2, column3 etc .. I want to write a loop that retrieves the information. So far I have tried:
<%
Dim counter, myStr
counter = 1 %>
<% Do while not rs.EOF %>
<% myStr=rs("column"&counter) %>
<%=myStr%> <br>
<%
rs.MoveNext
counter = counter+1
Loop
%>
Any help is greatly appreciated.
motorpilot
I am trying to reduce my asp coding by creating a loop that retrieves data from my SQL database. The database column entries are named column1, column2, column3 etc .. I want to write a loop that retrieves the information. So far I have tried:
<%
Dim counter, myStr
counter = 1 %>
<% Do while not rs.EOF %>
<% myStr=rs("column"&counter)
<%=myStr%> <br>
<%
rs.MoveNext
counter = counter+1
Loop
%>
Any help is greatly appreciated.
motorpilot
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect.
I had tried this solution before, but it looks as if my page was erroring for a different reason and I did not pick-up that the code was working....
Thanks,
motorpilot
I had tried this solution before, but it looks as if my page was erroring for a different reason and I did not pick-up that the code was working....
Thanks,
motorpilot
Great, glad to help
Hi,
If you want to retrieve all the fields in a recordset you have to specify another loop.
Try this:
<%
Dim counter
Do while not rs.EOF
for counter=1 to rs.fields.count
response.write(rs("column" & counter) & "<br>")
next
rs.MoveNext
Loop
%>
If you want to retrieve all the fields in a recordset you have to specify another loop.
Try this:
<%
Dim counter
Do while not rs.EOF
for counter=1 to rs.fields.count
response.write(rs("column"
next
rs.MoveNext
Loop
%>
You may try this piece of code, which will loop your data into html table
<table border='1' width="100%">
<tr bgcolor="FFFFFF">
<% For i=0 to dbRS.Fields.Count-1 %>
<td><b><%=dbRS(i).Name %> </b></td><% NEXT %></tr>
<% Do While Not dbRS.EOF
count = count + 1
color_code = right(count,1)
select case color_code
case "1","3","5","7","9"
color_code="#e6e6e6"
case else
color_code="#FFFFFF"
end select %>
<tr bgcolor="<%=color_code%>">
<% For i=0 to dbRS.Fields.Count-1 %>
<td ><% = dbRS(i) %> </td>
<% Next %>
</tr>
<% dbRS.MoveNext
Loop
%>
<table border='1' width="100%">
<tr bgcolor="FFFFFF">
<% For i=0 to dbRS.Fields.Count-1 %>
<td><b><%=dbRS(i).Name %> </b></td><% NEXT %></tr>
<% Do While Not dbRS.EOF
count = count + 1
color_code = right(count,1)
select case color_code
case "1","3","5","7","9"
color_code="#e6e6e6"
case else
color_code="#FFFFFF"
end select %>
<tr bgcolor="<%=color_code%>">
<% For i=0 to dbRS.Fields.Count-1 %>
<td ><% = dbRS(i) %> </td>
<% Next %>
</tr>
<% dbRS.MoveNext
Loop
%>
ASKER
I had tried this solution before, but it looks as if my page was erroring for a different reason and I did not pick-up that the code was working....
Thanks,
motorpilot