DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  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



Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links