DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Placing commas between returned values

  1. #1
    Roberta Gales Guest

    Placing commas between returned values


    I am pulling a set of skills to a job post page from a database. I want to
    insert commas between the skills, but none after the last skill. The previous
    page owner used

    SR = Stmt.executeQuery("SELECT skill from SKILL")
    String skills = "";
    while (SR.next()){
    skills += SR.getString("skill") + ", ";
    }
    String fmtSkills = skills.substring(0, skills.lastIndexOf(","));
    out.print(fmtSkills);

    on a JSP page, but I need to do the same thing in ASP. How can I do this?

  2. #2
    Michael Guest

    Re: Placing commas between returned values


    Roberta, here is one way to do it in ASP.
    (assuming same table being used)

    dim dbConn, skillsRS, skillsTotal, totalLeft

    set dbConn = server.createObject("adodb.connection")
    set skillsRS = server.createObject("adodb.recordset")
    set skillsTotal = server.createObject("adodb.recordset")

    dbConn.open(connection string here)

    skillsRS.open("select skill from SKILL"), dbConn
    skillsTotal.open("select count(skill) as total from SKILL"), dbConn

    totalLeft = skillsTotal("total")


    do while not skillsRS.eof
    if totalLeft > 1 then
    response.write(skillsRS("skill") & ", ")
    totalLeft = totalLeft - 1
    else
    response.write(skillsRS("skill"))
    end if
    skillsRS.moveNext
    loop

    skillRS.close
    set skillsRS = nothing
    skillsTotal.close
    set skillsTotal = nothing
    dbConn.close
    set dbConn = nothing

    Good luck!
    Michael


    "Roberta Gales" <roberta_gales@rac.ray.com> wrote:
    >
    >I am pulling a set of skills to a job post page from a database. I want

    to
    >insert commas between the skills, but none after the last skill. The previous
    >page owner used
    >
    >SR = Stmt.executeQuery("SELECT skill from SKILL")
    >String skills = "";
    >while (SR.next()){
    > skills += SR.getString("skill") + ", ";
    >}
    >String fmtSkills = skills.substring(0, skills.lastIndexOf(","));
    >out.print(fmtSkills);
    >
    >on a JSP page, but I need to do the same thing in ASP. How can I do this?



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center