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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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


    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!


    Build Forge Express demo: Enabling software delivery excellence for small and midsized businesses

    This demonstration gives you an overview of IBM® Rational® Build Forge Express Edition, a global offering that provides a framework to automate and execute software processes. Rational Build Forge provides a software assembly line that can support all of your tools, technologies, and platforms so you can achieve a repeatable, reliable, and traceable build and release process.
    FREE! Go There Now!


    NEW! "ebook: Exploring IBM SOA Technology & Practice

    Learn field-tested SOA principles, methodology, technology and implementation from the global SOA market leader - in a new e-book by an IBM SOA expert. Written by IBM Certified SOA Solution Designer Bobby Woolf, "Exploring IBM SOA Technology & Practice" is the ultimate insider's guide to SOA - a PDF e-book packed cover to cover with IBM's specific advice on how to make your SOA implementation a success.
    FREE! Go There Now!


    NEW! Accelerating Software Innovation on i on Power Systems

    Attend this launch webcast with Scott Hebner, Vice President of IBM Rational Marketing and Strategy, for an overview of Rational’s new software offerings and resources to help modernize and accelerate software innovation on i on Power Systems – while ensuring past application investments are protected and continue to grow. Learn how these solutions are helping customers extend their core i5/OS solutions toward modern architectures such as SOA and web technologies to deliver business improvements that stand the test of time.
    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! Hacking 101

    Join us for this web seminar to learn how you can defend your web applications from attack. Learn about the 3 most common web application attacks, including how they occur and what can be done to prevent them. We’ll also discuss manual versus automated approaches for scanning and identifying web application vulnerabilities and how IBM Rational AppScan, an automated vulnerability scanner, can help you automate more of what you are doing manually today.
    FREE! Go There Now!


    NEW! Hello World: Monitor a simple business process using WebSphere Business Monitor V6.0.2

    This tutorial shows new users of IBM WebSphere Business Monitor Version 6.0.2 how to perform the "Hello World" equivalent for monitoring business process applications. It is intended to help you get familiar with the capabilities of the product.
    FREE! Go There Now!


    NEW! IBM Enterprise Modernization Sandbox for System z

    IBM Enterprise Modernization solutions help organizations evolve core IT systems towards modern architectures and technologies—reducing the burden of maintenance and freeing up resources to develop new business requirements and capabilities. With the IBM Enterprise Modernization Sandbox for System z you can evaluate IBM Enterprise Modernization solutions focused on five key areas: Assets, Architectures, Skills, Processes and Infrastructures, and Investment. Each solution is based upon real customer experiences and offers a proven path to get you started with your modernization projects.
    FREE! Go There Now!


    NEW! Rational Talks to You: Scott Ambler on being agile in a global development environment

    Join this Rational Talks to You teleconference on December 6 at 1:00 pm ET to participate in an agile application development discussion and get your questions answered on using IBM Rational Method Composer in a distributed environment.Get your questions answered!
    FREE! Go There Now!


    NEW! The role of integrated requirements management in software delivery

    This paper is about the critical role that a discipline called integrated require­ments management can play in helping to ensure that your business goals and IT investments are continuously aligned—whether you are sourcing, integrat­ing, building or maintaining software. It also looks at ways that automated IBM Rational® products can work together to help you use requirements in the very best way.
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Functional Tester V7.0.1

    Get a free trial download of the latest version of IBM Rational Functional Tester V7.0.1. Rational Functional Tester is an automated functional and regression testing solution for QA teams concerned with the quality of their Java, Microsoft Visual Studio .NET, and Web-based 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-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek