?
Solved

ASP recordset string concatenation

Posted on 2003-03-28
9
Medium Priority
?
254 Views
Last Modified: 2006-11-17
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
0
Comment
Question by:motorpilot
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 

Accepted Solution

by:
jeremycase earned 200 total points
ID: 8225515
try creating a string first...

temp = "column" & counter
myStr = rs(temp)

I'm not sure, but I don't think you can concatenated inside the rs("").
0
 

Author Comment

by:motorpilot
ID: 8225700
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
0
 

Author Comment

by:motorpilot
ID: 8225714
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
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 

Expert Comment

by:jeremycase
ID: 8225821
Great, glad to help
0
 
LVL 3

Expert Comment

by:MManzanera
ID: 8226184
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
%>
0
 
LVL 7

Expert Comment

by:Alpha Au
ID: 8229240
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
%>
0

Featured Post

Quick Cloud Training

Looking for some quick training on the cloud in 2 hours or less? Check out these how-to guides in AWS, Linux, OpenStack, Azure, and more!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
The viewer will learn how to count occurrences of each item in an array.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question