ASP.NET
  Home arrow ASP.NET arrow Page 5 - 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 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
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
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 20
    2007-02-14

    Table of Contents:
  • Database Independent Development using ASP.NET 2.0
  • Developing a common class which works with Factories: source code
  • Developing a common class which works with Factories: explanation
  • Developing a simple data access class to work with the factory: skeleton
  • Developing a simple data access class to work with the factory: methods
  • Developing a simple data access class to work with the factory: methods extended

  • 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 - Developing a simple data access class to work with the factory: methods


    (Page 5 of 6 )

    This section explains the skeleton provided in the previous section. Before looking at the methods, if you can observe the declaration of the class DataAccess, it is derived (or inherited) from the DBFactory class. That means all the methods of the DBFactory class can be accessed as part of the DataAccess class.

    In simple terms, we can get Connection, Command and DataAdapter objects from the base class DBFactory itself. Furthermore, you can also instantiate and work with the DBFactory class directly!

    The following is the method which is used to execute any SQL statement in the database:

    Public Sub SQLExecute(ByVal sql As String)
     
    Dim cmd As DbCommand = GetDBCommand()
     
    cmd.CommandText = sql
     
    cmd.CommandType = CommandType.Text
     
    Try
       
    cmd.Connection.Open()
       
    cmd.ExecuteNonQuery()
     
    Catch ex As Exception
       
    Throw New Exception(ex.Message & "-->" & sql)
     
    Finally
       
    If cmd.Connection.State = ConnectionState.Open Then
         
    cmd.Connection.Close()
       
    End If
       
    cmd.Dispose()
     
    End Try
    End Sub

    In the above method, I am simply receiving the Command object from the GetDBCommand method available in the DBFactory class. Once the Command object is available, the process of executing the SQL statement is exactly the same as the traditional ADO.NET 1.1 approach.

    The following is the method which retrieves a set of rows in the form of a data table:

    Public Function GetDataTable(ByVal sqlSELECT As String) As DataTable
     
    Dim dt As New DataTable
     
    Dim da As DbDataAdapter = GetDBDataAdapter()
     
    Dim cmd As DbCommand = GetDBCommand()
     
    cmd.CommandText = sqlSELECT
     
    cmd.CommandType = CommandType.Text
     
    da.SelectCommand = cmd
     
    Try
       
    da.Fill(dt)
     
    Catch ex As Exception
       
    Throw New Exception(ex.Message & "-->" & sqlSELECT)
     
    Finally
       
    If cmd.Connection.State = ConnectionState.Open Then
         
    cmd.Connection.Close()
       
    End If
       
    cmd.Dispose()
       
    da.Dispose()
     
    End Try
     
    Return dt
    End Function

    In the above function, you can observe that I used both DataAdapter and Command objects (from the methods of DBFactory class) to fill the DataTable object.

    More ASP.NET Articles
    More By Jagadish Chaterjee


       · Hello guys! This is new series on database independent development using ASP.NET...
     

    ASP.NET ARTICLES

    - 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
    - Developing a Dice Game Using ASP.NET Futures...
    - Completing an ASP.NET AJAX Server-Centric Ba...
    - Information Management for an ASP.NET AJAX S...
    - Comment and Order Management for an ASP.NET ...
    - Back-end Management Tasks for an ASP.NET AJA...
    - User Information Management for an ASP.NET A...
    - Adding Comments and Search to an ASP.NET AJA...





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