Database Code
  Home arrow Database Code arrow Calling Stored Procedure through the Recor...
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 
Mobile Linux 
App Generation ROI 
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? 
DATABASE CODE

Calling Stored Procedure through the Recordset Object
By: aspfree
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 2
    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



    I discovered how to call stored procedures with less than 5 lines of code. I
    recently had to display a webpage that was based on a table that contained several
    calculated totals. The reason I had this summary/reporting table is a lot of data
    was calculated and allowed for almost anyway of displaying stat's about the data. 
    Here is a brief summary of what I did. I created a table in SQL 7 that held the
    data.

    Every 4 hours the table was refreshed with new data using a Stored
    Procedure. Then I created another Stored procedure that was being called
    from the ASP page. Without writing a book on what I did here is a 10,000 ft
    level overview. Hope this demo shows another way of using Stored Procedures to
    retrieve data a Data Source using ASP. Stored Procedures are no more than an SQL
    statement retreving data. Why hold that Query inside an ASP page when you can use
    the Database server to run your Query's


    Step 1



    Create a Reporting Table that will be populated with the totals. This is
    the SQL Generated Script that will created the table. This table holds all the
    calculated data that is based on Raw numbers that are inputted.


    <p>CREATE TABLE [dbo].[test2] (
    [NickName] [char] (50) NULL ,
    [TotalPoints] [int] NULL ,
    [Count_NickName] [char] (50) NULL ,
    [AvgScore] [decimal](18, 1) NULL ,
    [NumOfStrikes] [decimal](18, 0) NULL ,
    [WinLossPercentage] [decimal](18, 2) NULL ,
    [Wins] [int] NULL ,
    [Loses] [int] NULL
    ) ON [PRIMARY]
    GO
    </p>

    Step 1 1/2 Here is some data to load in the db.

    NickNameTotalPointsCount_NickNameAvgScoreNumOfStrikesWinning_PercentageWinsLoses
    NickName16111384.42852.97365
    NickName2445944.72857.455440
    NickName3419974.33549.484849
    NickName4383834.62451.814340
    NickName5337744.62054.054034
    NickName6329794.21455.74435
    NickName73248141645.683744


    Step 2

    Create Stored Procedure that will be called from an ASP page. Ok this is
    just a normal select statement but I'm convinced that put code where it will run the
    fastest. On the database server, you only have to call the stored Procedure and
    return the data. Instead of parsing the query and then running the statement.



    CREATE PROCEDURE [TestStoredProcedure] AS
    SELECT test2.NickName, test2.TotalPoints, test2.Count_NickName, test2.AvgScore,
    test2.NumOfStrikes, test2.WinLossPercentage, test2.Wins,test2.Loses
    FROM test2
    ORDER BY test2.NickName;
    GO


    Step 3

    Create an ASP page. The normal stuff, connection string, recordset object
    etc.. here is the code


    <% @language="vbscript" %>
    <%
    dim conn
    dim strconn
    dim rs
    dim strql

    'Normal Connection String
    strconn= "Driver={SQL
    Server};SERVER=127.0.0.1;UID=LoginID;PWD=password;DATABASE=some_db"
    set conn = server.createobject("adodb.connection")
    conn.open strconn


    'This is a local variable that holds the variable the execute the stored proc.
    <font color="#FF0000">strsql = "Exec TestStoredProcedure"
    set rs = server.createobject("adodb.recordset")
    rs.open strsql, conn

    %>
    <html>

    <head>
    <title>Example</title>
    </head>

    <body>
    <% rs.movefirst %>
    <table BORDER="1" width="80%">
    <tr></p>

    <p><td colspan="8"><center><b><strong>This section writes out
    the Names of the fields in the Recordse</strong>t</center></b></td></tr>
    <tr>
    <% For Each Field In RS.Fields %>


    <th>
    <%
    response.write "<b>" & Field.name & "</b>"
    %>
    </th>
    <% Next %>
    </tr>
    <tr></p>

    <td colspan="8"><center>This section writes out
    the DATA of the fields in the Recordset</strong></center></b></td></tr>
    <% Do While Not RS.EOF %>
    <tr>
    <% For Each Field In RS.Fields %>
    <td ALIGN="center">
    <%
    If IsNull(Field) Then
    Response.Write ""
    Else
    Response.Write Field.Value
    End If %>
    </td>
    <% Next
    RS.MoveNext %>
    <% Loop %>
    </table>
    </body>
    </html>
    <%
    'Close all objects and set to nothing to keep resources free!
    rs.close
    conn.close
    set rs = nothing
    set conn = nothing
    %></p>


    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 Database Code Articles
    More By aspfree

     

    IBM® developerWorks developerWorks - FREE Tools!


    IBM – Taking Web 2.0 to Work

    You'll get answers to many questions and more from David Barnes, Lead Evangelist for IBM Emerging Internet Technologies. David will discuss aspects of Web 2.0 that bring value to corporations, academia, and government. He'll also discuss IBM's vision around Web 2.0, including the importance of remixability and consumability. The discussion will culminate with examples of various IBM Software Group solutions you can use to get ahead of the Web 2.0 adoption curve.
    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! Rational 'Talks to You' Teleconference Series

    This Fall, IBM Rational talks to you directly through a special teleconference series giving you access to the best minds in IBM Rational - product experts and market thought leaders who will answer your questions during these pre-scheduled telephone conference calls. Register today!
    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! 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! Section 508 of the U.S. Rehabilitation Act: Web accessibility compliance

    Because access to government information continues to be an area of concern for many U.S. citizens with disabilities, the U.S. government enacted Section 508 of the Rehabilitation Act in 2001 to ensure that government agencies create accessible Web content, enabling all citizens to access the information they need. A fully accessible Web site makes Web content accessible to all individuals, including those with disabilities, who may be accessing Web content via a variety of user agents. Common user agents include standard Web browsers, text-only browsers, assistive devices and mobile devices such as cell phones or personal digital assistants (PDAs).
    FREE! Go There Now!


    NEW! Try IBM Rational Asset Manager V7.0 online!

    You can now evaluate IBM Rational Asset Manager V7.0 online without installing or configuring it on your own system! Rational Asset Manager helps create, modify, govern, find, and reuse any type of development assets, including SOA and systems development assets. Rational Asset Manager helps you reduce software development costs and improve quality by facilitating the reuse of all types of software development-related assets. Visit developerWorks to learn more about this product and register to explore its capabilities online.
    FREE! Go There Now!


    NEW! Webcast: Striking the right balance between manual and automated testing

    Join this webcast to learn how IBM Rational's Functional Testing solution enables you to implement automation your way, at your pace, with your existing staff. In this webcast, you’ll learn how you can eliminate redundancy of manual test scripts, reduce errors, and increase test coverage through test automation. After this presentation you will understand how IBM Rational Functional Testing solution can streamline your manual testing and make test automation easily attainable.
    FREE! Go There Now!


    NEW! Webcast: WebSphere Process Server

    WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies.
    FREE! Go There Now!


    NEW! Webcast: What is new in Viper 2 for developers?

    Viper 2 brings a great value to developer communities including SQL, XML, PHP, Ruby, .NET and Java. You probably already know that DB2 Express-C is free for developers to develop, deploy and distribute. Viper 2 provides a variety of means that help move your application from the development stage to deployment more rapidly. This webcast shows how to best utilize the latest tools available for developing DB2 applications.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    DATABASE CODE ARTICLES

    - Deployment of the MobiLink Synchronization M...
    - MobiLink Synchronization Wizard in SQL Anywh...
    - Finding Matching Records in Data Access Pages
    - Using the AccessDataSource Control in VS 2005
    - A Closer Look at ADO.NET: The Command Object
    - A Closer Look at ADO.NET: The Connection Obj...
    - Using ADO to Communicate with the Database, ...
    - Code Snippets: Counting Records
    - Constraints In Microsoft SQL Server 2000
    - Multilingual entries into a DB and to be dis...
    - Getting A List of Tables From SQL Server
    - SQL Server Database Creator - .NET Version
    - ADO Recordset Paging
    - Two combos, one textbox example
    - Discussion & Listserv Module by Mike Eck...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT