MS SQL Server
  Home arrow MS SQL Server arrow A Wrapper Class for the SQL Server Based D...
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 
VeriSign Whitepapers 
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? 
MS SQL SERVER

A Wrapper Class for the SQL Server Based Data Access Helper
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2006-08-23

    Table of Contents:
  • A Wrapper Class for the SQL Server Based Data Access Helper
  • Getting a single row or single value from the data access helper
  • Getting multiple rows using wrapper methods from the data access helper
  • Adding wrappers for transactions
  • A Wrapper method to test whether a row exists
  • Adding a wrapper to execute SQL statements
  • Adding miscellaneous wrapper 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

    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

    A Wrapper Class for the SQL Server Based Data Access Helper


    (Page 1 of 7 )

    This article explains to you the techniques required to develop a wrapper class for the data access helper developed in previous articles.
    There are two downloadable zip files available for this article. You can find them here and here.

    This is an extension to my previous articles; it is not an introductory article to COM+ or ADO.NET.  I suggest you to refer my previous articles before continuing with this one. If you are very new to COM+, I suggest you go through one of my previous articles here.

    I developed this wrapper class for extensibility. Currently, it works only with SQL Server. But you can add few more COM+ classes and link this wrapper very easily, due to its extensibility.

    The entire source code for this article is available in the form of downloadable zip files. The solution was developed using Microsoft Visual Studio 2003 Enterprise Architect with Microsoft SQL Server 2005 Developer Edition on Microsoft Windows Server 2003 Enterprise Edition.  Even though I believe that the source code available with this contribution can work with Microsoft Visual Studio.NET 2002, I didn’t really test it in any other environment. I request that you post in the discussion area if you have any problems with execution.

    Designing the wrapper for extensibility

    Let us consider the following code fragment:

    PublicEnum DBConnType

        MSSQL

    EndEnum

    PublicClass DBLib

        Friend ObjLib As Object 'can be used flexibly in any of the sub-classes

        Private arTransCommands As ArrayList

        Private _ConnectionString As String

        Private _ConnectionType As DBConnType

        Public Sub New(ByVal ConnectionType As DBConnType, ByVal ConnectionString As String)

            Try

                _ConnectionString = ConnectionString

                _ConnectionType = ConnectionType

                If Len(Trim(_ConnectionString & "")) = 0 Then Throw New Exception("Connection String not configured")

            Catch ex As Exception

                Throw New Exception(ex.Message & ". Invalid Database Configuration -->Error Logged")

            End Try

        End Sub

    Currently, I developed the above only for the SQL Server type of database connection. When you require support for more than one database, you will add a few more database types to the enumeration. 

    The variable “arTransCommands” is mainly used to add all the commands which need to be executed as a single transaction.

    The following is the code needed to work with the respective database related object:

    FriendFunction getDBHelperObject() As Object 'can be used flexibly in any of the sub-classes

            Select Case _ConnectionType

                Case DBConnType.MSSQL

                    Dim dbhelper As New CoreMSSQLDataAccessHelper.CDataAccess

                    dbhelper.ConnectionString = _ConnectionString

                    Return dbhelper

                Case Else

                    Throw New Exception("This library doesn't support the database '" & _ConnectionType.ToString & "'")

            End Select

        End Function

    You need to add a few more cases to the above method when you work with multiple databases.

    More MS SQL Server Articles
    More By Jagadish Chaterjee


       · Hello guys! Now, I extended the data access helper with a wrapper class. enjoy
     

    MS SQL SERVER ARTICLES

    - Completing the Introduction to Transact-SQL
    - A Brief Introduction to Transact-SQL
    - Lookups and Blocking Bad Data
    - Field Validation Rules for Blocking Bad Data
    - Using Masks to Block Bad Data
    - Blocking Bad Data
    - Using @@ROWCOUNT and TABLE Variables for Dat...
    - How to Use Variables, IF and CASE in Databas...
    - Creating Important Aspects of Notification S...
    - Working wth Variables in Database Interactio...
    - Delving Deeper into Notification Services
    - Notification Services
    - Building a Multi-table Report with SQL 2005 ...
    - A Secure Way of Building Connection Strings
    - Transferring a Database Using the SSIS Desig...





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