Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 5 - Implementing OOP to Develop Database Orien...
Iron Speed
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 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM Rational Software Development Conference
 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? 
VISUAL BASIC.NET

Implementing OOP to Develop Database Oriented Applications using VB.NET 2005
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 24
    2007-01-22

    Table of Contents:
  • Implementing OOP to Develop Database Oriented Applications using VB.NET 2005
  • Developing a class which holds an entire row in a table
  • Developing a class which holds a set of rows belonging to the same table
  • Developing a factory class to update rows to the database
  • Developing a class to interact with databases
  • Developing the application

  • 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
     
     
    Iron Speed
     
    ADVERTISEMENT

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Implementing OOP to Develop Database Oriented Applications using VB.NET 2005 - Developing a class to interact with databases
    (Page 5 of 6 )

    You can observe that the class in the previous section works with another class called “DBHelper.”  This class is mainly responsible for interacting with the database independently of any type of object.  The following is the code for the class:

    ImportsSystem.Data.SqlClient

    PublicClass DBHelper

        Private Shared Function getConnectionString() As String

            Return
    System.Configuration.ConfigurationManager.ConnectionStrings
    ("SampleDB").ConnectionString

        End Function

        Public Shared Sub SQLExecute(ByVal strSQL As String)

            Dim Conn As New SqlConnection(getConnectionString)

            Dim cmd As New SqlCommand(strSQL, Conn)

            With cmd

                .Connection.Open()

                .ExecuteNonQuery()

                .Connection.Close()

                .Dispose()

            End With

        End Sub

        Public Shared Function getRow(ByVal strSELECT As String) As
    DataRow

            Dim da As New SqlDataAdapter(strSELECT,
    getConnectionString)

            Dim dt As New DataTable

            da.Fill(dt)

            da.Dispose()

            If dt.Rows.Count = 0 Then Return Nothing Else Return
    dt.Rows(0) 'return only first row

        End Function

        Public Shared Function getDataTable(ByVal strSELECT As
    String) As DataTable

            Dim Conn As New SqlConnection(getConnectionString)

            Dim da As New SqlDataAdapter(strSELECT, Conn)

            Dim dt As New DataTable

            da.Fill(dt)

            da.Dispose()

            Return dt

        End Function

        Public Shared Function getRowValue(ByVal strSELECT As String)
    As String

            Dim Conn As New SqlConnection(getConnectionString)

            Dim cmd As New SqlCommand(strSELECT, Conn)

            Dim value As String = ""

            With cmd

                .Connection.Open()

                value = .ExecuteScalar() & "" 'concatenating an empty
    string..to eliminate null or nothing

                .Connection.Close()

                .Dispose()

            End With

            Return value

        End Function

    EndClass

    At this point, I didn’t include any mapping to stored procedures in the above class. It is a very simple data access class with very few routines. For a better data access class, you can try to use Microsoft Enterprise Library 2.0 with the above DBHelper class to make it more robust. If you are new to that, I suggest you check out my other articles on that topic at www.aspfree.com/cp/bio/Jagadish-Chatarji.

    More Visual Basic.NET Articles
    More By Jagadish Chaterjee


       · This is a simple introduction to developer OOP based database applications using...
       · Excellent article. Jag is a great teacher.keep up the good work
     

    VISUAL BASIC.NET ARTICLES

    - Types of Operators in Visual Basic
    - Operators
    - Understanding Custom Events using Visual Bas...
    - Polymorphism using Abstract Classes in Visua...
    - Shadowing using Shadows in Visual Basic.NET ...
    - Overloading and Overriding in Visual Basic.N...
    - More on Controlling Windows Fax Services Usi...
    - Programmatically Controlling Windows Fax Ser...
    - Focusing on Forms and Menus in Visual Basic
    - Manipulating Forms with the Windows Forms Li...
    - Basics of the Windows Forms Library
    - Forms, Controls, and Other Useful Objects
    - Implementing OOP to Develop Database Oriente...
    - Using Themes and Skins for Personalization w...
    - A Deeper Look at Personalization using Visua...

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




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