Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

ASP recordset string concatenation

Posted on 2003-03-28
9
Medium Priority
?
258 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
6 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month12 days, 2 hours left to enroll

564 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