SQL Select into ASP Array


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: SQL Select into ASP Array

  1. #1
    drew Guest

    SQL Select into ASP Array


    Iím trying to select data from a SQL database and place the data into an array
    in an ASP page. Can this be accomplished? If it can could someone provide
    me with an example of the code that will do this. Iím quit confused at this
    point on how the select can place data into the array. Can this data in
    the array be sorted though once itís in the array?

    Thanks in advance for you time.

    drew

  2. #2
    mister pants Guest

    Re: SQL Select into ASP Array


    <%
    <<open recordset>>

    lCount = 0
    If Not rs.EOF Then
    rs.MoveLast
    lCount = CLng(rs.RecordCount)
    rs.MoveFirst
    End If

    Redim aCode(lCount, 2)

    lCount = 0
    Do Until rs.eof

    aCode(lCount, 1) = rs.Fields("<field 1>")
    aCode(lCount, 2) = rs.Fields("<field 2>")

    lCount = lCount + 1
    rs.Movenext

    Loop

    %>

    The reason this code does not dynamically resize the array as it loops through
    the recordset is that only the last element in an array can be resized, so
    the array is sized (x, y) before the loop starts.

    You could also use a collection object or a Dictionary object if necessary.
    For client side code I usually transfer the server array into a Dictionary
    object.




    "drew" <dcorazza@essilorusa.com> wrote:
    >
    >Iím trying to select data from a SQL database and place the data into an

    array
    >in an ASP page. Can this be accomplished? If it can could someone provide
    >me with an example of the code that will do this. Iím quit confused at

    this
    >point on how the select can place data into the array. Can this data in
    >the array be sorted though once itís in the array?
    >
    >Thanks in advance for you time.
    >
    >drew



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