ASP Code
  Home arrow ASP Code arrow How to use the nextrecordset to write out ...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP CODE

How to use the nextrecordset to write out multiple recordsets in one call to the database. Very Hand
By: aspfree
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    1999-09-01

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Using the NEXTRECORDSET method to write out multiple SELECT statements from one connection.


    A formatted string gets passed to the database via a Recordset object.
         (below is this examples formatted string.)

    Sql Statement that is passed to the database

    DECLARE @Id_Req INT exec sp_EmpInfo 'John ','Smith', '123 main Street', 'Hollywood', @Id_Req OUTPUT SELECT * FROM AllData WHERE RecordId = @Id_Req SELECT AllData.fname, AllData.lname FROM Alldata WHERE RecordId = @Id_Req SELECT AllData.fname FROM AllData WHERE RecordId = @Id_Req SELECT AllData.lname FROM AllData WHERE RecordId = @Id_Req SELECT AllData.Address FROM AllData WHERE RecordId = @Id_Req SELECT AllData.city FROM AllData WHERE RecordId = @Id_Req

    Output of the multiple recordsets formatted on an ASP Page. 

    Contents of recordset #1
    RecordIDfnamelnameaddresscity
    58JohnSmith123 main StreetHollywood
    Contents of recordset #2
    fnamelname
    JohnSmith
    Contents of recordset #3
    fname
    John
    Contents of recordset #4
    lname
    Smith
    Contents of recordset #5
    Address
    123 main Street
    Contents of recordset #6
    city
    Hollywood

    4. Code of the asp page.

    <%
    dim conn
    dim strconn
    dim rs
    dim strsql
    dim strsql2
    dim strsql3
    dim strsql4
    dim strsql5
    dim strsql6
    dim strsql7
    dim strsql8

    'strconn = Driver={SQL Server};Description=example;SERVER=222.222.1.2;UID=webexample;

    PWD=;DATABASE=webexample"


    '
    Format Declare & EXEC statements that will be passed
    'to the database with the output parameters

    strsql = "DECLARE " & CHR(10) & "@Id_Req " & "INT" & CHR(10)
    strsql2 ="exec " & "sp_EmpInfo" & " '" & request("txtFirstName") & "'," & "'" & request("txtLastName") & "', " & "'" & request("txtaddress") & "', " & "'" & request("txtcity") & "', "& "@Id_Req " & "OUTPUT" & chr(10)

    '
    Formats one or more sql statements that will be passed to the
    'database In this examples I use six different ways.

    strsql3 ="SELECT * FROM AllData WHERE RecordId = @Id_Req"
    & Chr(10)
    strsql4 ="SELECT AllData.fname, AllData.lname FROM Alldata WHERE
    RecordId = @Id_Req" & Chr(10)
    strsql5 ="SELECT AllData.fname FROM AllData WHERE RecordId =
    @Id_Req" & Chr(10)
    strsql6 ="SELECT AllData.lname FROM AllData WHERE RecordId =
    @Id_Req" & Chr(10)
    strsql7 ="SELECT AllData.Address FROM AllData WHERE RecordId =
    @Id_Req" & Chr(10)
    strsql8 ="SELECT AllData.city FROM AllData WHERE RecordId =
    @Id_Req" & Chr(10)

    '
    Puts together all of the local variables into one variable
    'That will be used by the recordset object

    strsql = strsql & strsql2 & strsql3 & strsql4 & strsql5 & strsql6 &
    strsql7 & strsql8

    '
    This is optional this writes out the strsql local variable
    'that will be passed to the database

    response.write "<b>" & "Sql Statement that is passed to the
    database" & "</b>" & "<br>"
    response.write strsql & "<br>" & "<br>"

    'sets a connection & recordset objects and executes the strsql
    local variable

    set conn = server.createobject("adodb.connection")
    conn.open strconn
    set rs = server.createobject("adodb.recordset")
    rs.open strsql, conn

    '
    Parses out the individual recordsets and places them
    'into individual table rows

    intcount = 1
    Do Until rs Is Nothing
    response.write "<table border='1' width='25%'>"   

        response.write "<b> Contents of recordset #" & intCount &
    "</b><br>"
    'Parses out the individual recordsets and places them into table rows
        Do While Not rs.EOF
            response.write "<TR>"
            For Each oField In RS.Fields
        response.write "<TH>" & oField.Name & "</TH>"
        Next
            Response.write "</TR>" & "<TR>"
            For Each oField In RS.Fields
    response.write "<TD ALIGN=center>"
    If IsNull(oField) Then
    Response.Write "&nbsp;"
    Else
    Response.Write oField.Value
    End If
    response.write "</TD>"
            Next
            rs.MoveNext
        Loop
    'Uses the NEXTRECORDSET Method
        Set rs = rs.NextRecordset
        intCount = intCount + 1
    response.write "</table>"
    Loop
    %>

     


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More ASP Code Articles
    More By aspfree

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! Driving Business Success with Rational Process Library

    Join this webcast, to learn how the Rational Process Library can help with compliance issues, drive process improvement, and assist in service-oriented architecture (SOA) or Agile development. We will take a peek into the Rational Process Library with content around software and systems engineering (including RUP), operations and systems management, program and portfolio management, and asset and SOA governance.
    FREE! Go There Now!


    NEW! Calling all CC Power Users – and those that would like to be!

    Join this Rational Talks to You teleconference, featuring Paul Boustany and Mark Krasovich, to speak to the experts about becoming a Rational ClearCase power user. Get a chance to ask your questions and learn tips and tricks for using Rational ClearCase in Agile development
    FREE! Go There Now!


    NEW! BlammoSplat: Build a community Web site of OpenLaszlo animations, Part 3: The community animation

    Learn to enable users to both rate existing animations and to combine existing animations into new snippets. This is the third in a series of three tutorials that chronicle the building of a site that enables collaborative discussion and animation building using Domino and OpenLaszlo.
    FREE! Go There Now!


    NEW! Evaluate IBM Lotus Sametime Standard V8.0

    Visit IBM developerWorks to download a free trial of the latest release of IBM Lotus Sametime Standard V8.0. Lotus Sametime Standard V8.0 is a platform for unified communications and collaboration that combines security features with an extensible, open solution including integrated Voice over IP, geographic location awareness, mobile clients, and a robust Business Partner community offering telephony and video integration.
    FREE! Go There Now!


    NEW! Evaluate Rational Business Developer V7.1

    Visit IBM developerWorks to download a free trial version of IBM Rational Business Developer V7.1. Rational Business Developer offers rapid and simplified development of business applications and services through Enterprise Generation Language (EGL) tools, generating Java or mainframe solutions while shielding developers from technical complexities.
    FREE! Go There Now!


    NEW! Innovate don't duplicate! Asset reuse strategies for success

    Asset Reuse is a key strategy for companies looking to create innovative solutions to solve complex software development problems. Searching for, identifying, updating, using and deploying software assets can be a difficult challenge. Listen to this webcast, to learn about strategies and tools that you can leverage for a successful project, including Rational Asset Manager, Rational Software Architect and WebSphere Service Registry and Repository.
    FREE! Go There Now!


    NEW! Rational Build Forge Express eKit

    Rational Build Forge Express Edition is an automation framework that packages the latest enterprise-grade technologies into a reliable, flexible and robust configuration designed and priced specifically for small to midsize businesses. The new Rational Build Forge Express eKit provides you with valuable resources – including a case study, podcast, demo, and articles – to help you increase staff productivity, compress development cycles and deliver better software, fast.
    FREE! Go There Now!


    NEW! Software Change and Configuration Management Solution Guidelines

    This whitepaper provides areas to consider when evaluating any software configuration management solution. It addresses how the IBM solutions (Rational ClearCase and Rational ClearQuest) meet the needs and requirements of both project leaders and developers to provide successful Software Change and Configuration Management.
    FREE! Go There Now!


    NEW! Webcast: Accelerating Software Innovation with System z

    Attend this launch webcast with Scott Hebner, Vice President of IBM Rational Marketing and Strategy, where he will overview Rational’s new offerings and programs to help customers accelerate software innovation on System z. He will discuss how these solutions help organizations extend their core business processes toward modern architectures such as SOA and web technologies to deliver business improvements that stand the test of time.
    FREE! Go There Now!


    NEW! Webcast: Extreme transaction processing with WebSphere Extended Deployment

    In this webcast, you'll get an introduction to the eXtreme Transaction Processing (XTP) features of WebSphere Extended Deployment and the common architectural traits required by XTP applications. See how WebSphere Extended Deployment's ObjectGrid feature provides a state-of-the-art infrastructure for hosting XTP applications.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    ASP CODE ARTICLES

    - ASP Forms
    - ASP: The Beginning
    - Getting Remote Files With ASP Continued
    - Inbox and Outbox Manipulation in ASP
    - Relational DropDownList Using VB.NET
    - Ad Tracking URL Hits
    - Use ViewState to display one record per page...
    - Send Email using ASP.NET formatted in HTML
    - ASP File Explorer
    - ASP/XML Interview questions by Srivatsan Sri...
    - Various methods of setting Date values to a ...
    - Conditional DataGrid Item and using checkbox...
    - Fill .NET Listbox with SQL DataReader
    - Filling Dropdown box using Code-Behinds in C#
    - FLAMES code sample written in .NET What is F...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway