ASP.NET
  Home arrow ASP.NET arrow Database Independent Development using ASP...
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? 
ASP.NET

Database Independent Development using ASP.NET 2.0: Dealing with Stored Procedures
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 14
    2007-02-21

    Table of Contents:
  • Database Independent Development using ASP.NET 2.0: Dealing with Stored Procedures
  • Adding parameters to the cache
  • Executing a stored procedure as part of the Data Access Layer
  • Returning result sets (or a set of rows) by executing a stored procedure
  • Returning a single row or single value by executing a stored procedure
  • Testing the execution of stored procedures (in ASP.NET) using DAL methods

  • 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


    Database Independent Development using ASP.NET 2.0: Dealing with Stored Procedures


    (Page 1 of 6 )

    This is the second part of a two-part article. In the previous part we focused on developing database independent applications using ASP.NET 2.0. In this part, we will extend the functionality of the data access layer to the stored procedure level.
    A downloadable zip file is available for this article.

    I strongly suggest that you go through the first part of this series, if you are new to database independent development in .NET 2.0.

    The entire solution (source code) for this article is available as a free download (in the form of a zip). All the applications in this series have been developed using Microsoft Visual Studio 2005 Professional Edition on Microsoft Windows Server 2003 Standard Edition together with Microsoft SQL Server 2005 Express Edition and Oracle 10g Express Edition as the database. I didn't really test any of the code in any other tools/IDEs/servers/editions/versions. If you have any problems, please feel free to post in the discussion area.

    Defining a class to hold the details of a stored procedure parameter

    When we deal with stored procedures, we quite often work with parameters as well. To hold the information of a parameter, I would like to define my own class as follows:

    Imports System.Data.Common

    Public Class SPParameter

       Public ParameterName As String
       
    Public ParameterValue As Object
       
    Public ParameterDataType As DbType
      
    Public ParameterSize As Integer
      
    Public ParameterDirectionUsed As ParameterDirection

       Public Sub New()

       End Sub

       Public Sub New(ByVal passedParameterName As String, ByVal passedValue As Object, Optional ByVal passedSQLType As DbType = Nothing, Optional ByVal passedSize As Integer = Nothing, Optional ByVal passedDirection As ParameterDirection = ParameterDirection.Input)
        
    ParameterName = passedParameterName
        
    ParameterValue = passedValue
        
    ParameterDataType = passedSQLType
        
    ParameterSize = passedSize
        
    ParameterDirectionUsed = passedDirection
       
    End Sub

    End Class

    The above class simply holds the name and value of the stored procedure parameter along with other information like type, size and direction (IN, OUT, IN OUT or RETURN).

    Developing a separate class to hold parameter information is very helpful if you would like to scale your layer (data access layer) to meet multi-tier architectures and requirements. For example, you can make the above class serializable by modifying it as follows:

    Imports System.Xml.Serialization
    Imports System.Data.Common

    <XmlRoot("SPParameter")> _
    Public Class SPParameter

       <XmlElement("ParameterName", GetType(String))> _
       
    Public ParameterName As String

       <XmlElement("ParameterValue", GetType(Object))> _
      
    Public ParameterValue As Object

       <XmlElement("ParameterDataType", GetType(DbType))> _
      
    Public ParameterDataType As DbType

       <XmlElement("ParameterSize", GetType(Integer))> _
      
    Public ParameterSize As Integer

       <XmlElement("ParameterDirectionUsed", GetType(ParameterDirection))> _
      
    Public ParameterDirectionUsed As ParameterDirection

    .
    .

    End Class

    More ASP.NET Articles
    More By Jagadish Chaterjee


       · Hello guys. This is second in the series focusing on "database independent...
       · Thanks for the article. Wondering whether can you still have a database independent...
       · Jag,Thank you so much for your article. I have been building a web appication...
       · Jag,How would you set the SPExecute if you wanted to return a Int (for example)...
     

    ASP.NET ARTICLES

    - Disadvantages of the ASP.NET MVC Framework
    - Advantages of the ASP.NET MVC Approach
    - ASP.NET Web Forms Weaknesses
    - ASP.NET Web Forms Meets ASP.NET MVC
    - Source Code for Saving and Retrieving Data w...
    - Using GridView to Save and Retrieve Data wit...
    - Handling Dynamic Images in ASP.NET 3.5 AJAX ...
    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX
    - Building a Simple Storefront with LINQ





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