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  
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? 
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!


    Be the first to hear about i5/OS V6R1!

    Hold your calendar on January 30, 2008 for this free webcast on the new i5/OS. Rational's Enterprise Modernization products will be discussed at this webcast as they help to drive the application development environment for this new System i OS. <br />And learn how i5/OS will take you to the next step of efficient, resilient business processing. You will hear about the new i5/OS capabilities as it will be the most significant i5/OS release in years. If you cannot join the webcast on 1/30/08 you can still use this link to listen to the replay.<br />
    FREE! Go There Now!


    NEW! Download a free trial of Lotus Quickr 8.0

    Visit IBM developerWorks to download a free trial version of Lotus Quickr 8.0, which enables collaboration by transforming the way everyday business content such as documents, rich media, photos, and video can be shared. Lotus Quickr makes it faster and easier to share content of all types (not just documents) within virtual teams. It is designed to make it easier to collaborate across organizational boundaries, while continuing to work within the context of familiar desktop applications.
    FREE! Go There Now!


    NEW! Evaluate WebSphere Extended Deployment Compute Grid V6.1

    Visit IBM developerWorks to download a free trial version of WebSphere Extended Deployment Compute Grid, which lets you schedule, execute, and monitor batch jobs. Because online transaction processing and batch jobs execute simultaneously on the same server resources, you can avoid costly duplication of resources. Compute Grid supports job types of Java transactional batch, compute-intensive and a new type called "native execution", which enables non-Java workloads to run on distributed end points.
    FREE! Go There Now!


    NEW! Hello World: WebSphere Service Registry and Repository

    Manage, govern, and share services across your organization by using WebSphere Service Registry and Repository. Follow the hands-on exercises to learn how to navigate the Web interface to publish, find, reuse, and update services.
    FREE! Go There Now!


    NEW! IBM Enterprise Modernization Sandbox for System z: Architecture

    Analysts, architects, and developers who have existing COBOL or PL/I skills and want to extend those skills to deploy new workloads on the mainframe can use the IBM Enterprise Modernization Sandbox for System z to find hands-on walkthroughs of common real world scenarios. The scenarios provide examples of how to rapidly design, create, assemble, test, and deploy high-quality Web, Web services, portal, and SOA applications for IBM CICS, IBM IMS, and IBM WebSphere Application Server.
    FREE! Go There Now!


    NEW! Run your first CICS application on a PC using TXSeries for Windows

    Learn the basics of the IBM Customer Information Control System (CICS). With a hands-on exercise, learn how to get your first CICS application up and running on your desktop using TXSeries V6.1 for Windows. The tutorial shows you how to download and install a free trial version of TXSeries V6.1.
    FREE! Go There Now!


    NEW! Using Rational Business Developer to enhance your developer productivity

    Join this Rational Talks to You teleconference, to hear how Enterprise Generation Language (EGL) eliminates the need for tedious and error-prone low level coding, so developers can focus on business requirements. EGL extends the Rational software development platform with a simplified programming language that enables developers who have little or no experience with Java, Web technologies or Service Oriented Architecture, to create enterprise-class applications and services quickly and easily. It also allows developers who may have little or no mainframe programming experience to quickly create traditional mainframe components.
    FREE! Go There Now!


    NEW! Webcast: IBM Rational Build Forge - Beyond the Build

    The discipline of assembling and delivering software is maturing beyond standard developer-centric compile/test software builds. The end-to-end software development lifecycle is emerging as the new focus moves “Beyond the Build.” Join this on demand webcast to learn about methods for streamlining software delivery and key capabilities of the IBM Rational Build Forge framework for automating build and release management in environments of any size.
    FREE! Go There Now!


    NEW! Whitepaper: Achieving consistency between business process models and operational guides

    Explore how Rational and WebSphere software enable enterprise documentation in SOA environments. Specifically, a new integration between IBM WebSphere® Business Modeler and IBM Rational® Method Composer software can help technical writers more easily keep enterprise operations manuals in sync with changes that are made to business processes, resulting in more accurate and timely documentation that benefits the entire enterprise.
    FREE! Go There Now!


    Refresh! IBM Rational Systems Development Solution eKit

    With IBM Rational Systems Development Solution, you can deliver products faster with higher quality. Within this kit, Read the “Model Driven Systems Development” white paper to see how to improve product quality and communication. Then check out the rest of the e-Kit to learn more about important topics that can affect the success of any software project through customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems. From start to finish, at every stage in your projects, Rational Systems Development Solution can help your company reach its full potential.
    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-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek