Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 747005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:09:21+00:00 2026-05-14T14:09:21+00:00

I have a classic asp webpage written in vbscript that outputs the results from

  • 0

I have a classic asp webpage written in vbscript that outputs the results from a third-party stored procedure. My user wants the page to display the columns of data in a different order than they come in from the database. Is there an easy and safe way to re-order the columns in an ADO recordset?

I did not write this page and cannot change the SP.
What is the minimum change I can make here to get the job done and not risk screwing up all the other stuff in the page?

The code looks something like

dim Conn, strSQL, RS
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open ServerName

Set strSQL = "EXEC storedProc @foo = " & Request("fooParam")
'This stored procedure returns a date column, an arbitrary '
' number of data columns, and two summation columns.  We '
' want the two summation columns to move so they appear '
' immediately after the data column '

Set RS = Server.CreateObject("ADODB.RecordSet")
RS.ActiveConnection = Nothing
RS.CursorLocation = adUseClient
RS.CursorType = adOpenStatic
RS.LockType = adLockBatchOptimistic
RS.Open strSQL, Conn, adOpenDynamic, adLockOptimistic

dim A

' ----- '
' Insert some code here to move the columns of the RS around '
' to suit the whim of my user '
' ----- '


' Several blocks of code that iterate over the RS and display it various ways '
RS.MoveFirst
For A = 0 To RS.Fields.Count -1
    ' do stuff '
Next

...

RS.MoveFirst
For A = 0 To RS.Fields.Count -1
    ' do more stuff '
Next

RS.Close : Set RS = Nothing
Conn.Close : Set Conn = Nothing
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:09:21+00:00Added an answer on May 14, 2026 at 2:09 pm

    Get the column names, then set up an ordering for them:

    dim ColumnNames
    set ColumnNames = CreateObject( "Scripting.Dictionary" )
    For A = 0 To RS.Fields.Count -1
      ColumnNames.Add A, RS.Fields(A).Name
    Next
    

    Here, ColumnNames holds the name of the column to use for each position. Applying whatever rules make sense, you can now change the ordering like so:

    '' swap order of columns 1 and 2
    dim temp
    temp = ColumnNames.item( 1 )
    ColumnNames.item( 1 ) = ColumnNames.item( 2 )
    ColumnNames.item( 2 ) = temp
    

    Finally, to get the new order, print as follows:

    For A = 0 To RS.Fields.Count -1
      Response.write( ColumnNames.item( A ) )
    Next
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is ADO in classic ASP. I have a stored procedure with a parameter
We have a classic ASP application that simply works and we have been loathe
I have a large classic ASP app that I have to maintain, and I
I have been developing in asp.net since its existence (also classic asp before that)
I have recently inherited a website written in Classic ASP, and am currently trying
I am moving from classic ASP to ASP.NET and have encountered what many of
I have a 3rd party server which has a classic ASP page which takes
I have a Word .DOCument that's being generated by a (classic ASP) server. It's
I have this classic ASP web application. Each user must login and their most
Let's say I have some Classic ASP pages that produce all output via Response.Write.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.