Visual Basic.NET
  Home arrow Visual Basic.NET arrow An Introduction to Object Oriented Databas...
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 
 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

An Introduction to Object Oriented Database Development with VB.NET 2005
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 13
    2006-07-12

    Table of Contents:
  • An Introduction to Object Oriented Database Development with VB.NET 2005
  • Explaining the class
  • Explanation continued
  • Expanding the class to handle errors
  • Further expanding the class to handle additional rows

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

    An Introduction to Object Oriented Database Development with VB.NET 2005
    (Page 1 of 5 )

    This article introduces you to object oriented programming for database development using Visual Basic.NET 2005. It explains classes, fields, methods, and objects.
    A downloadable file for this article is available here.

    For this article, I assume that you know enough about the basics of working with VB.NET controls, ADO.NET, and so forth using Visual Basic.NET 2005.  Even though this article only covers the basics of object-oriented programming along with database development, I shall extend it in the form of a series to cover the most advanced topics in Visual Basic.NET 2005.  You do not need to be familiar with OOP to understand this article.

    The entire source code for this article is available at the link indicated above in the form of a downloadable zip file. The solution was developed using Microsoft Visual Studio 2005 Professional Edition 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 article can work with Microsoft Visual Studio.NET 2003/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.

    To make this article simple, I created a sample database named “sample,” with a table “emp” containing the columns empno (string), ename (string), sal (double) and deptno (integer) and a few rows.

    Developing database interactions in a separate class: source code

    Once you open the downloadable solution, you will be able to find a file named “emp.vb” in the solution explorer.  Double click on it to open and you will find the following source code in it:

    ImportsSystem.Data.SqlClient

    PublicClass Emp

        Public m_empno As String
        Public m_ename As String
        Public m_sal As Double
        Public m_deptno As Integer

        Public Sub load(ByVal empno As String)
            m_empno = empno
            Dim cn As New SqlConnection("Data Source=.sql2k5;initial catalog=sample;user id=sa;password=eXpress2005")
            Dim cmd As New SqlCommand("select * from sample.dbo.emp where empno='" & empno & "'", cn)
            cmd.Connection.Open()
            Dim rd As SqlDataReader = cmd.ExecuteReader
            rd.Read()
            m_ename = rd("ename")
            m_sal = rd("sal")
            m_deptno = rd("deptno")
            cmd.Connection.Close()
            cmd.Dispose()
            cn.Dispose()
        End Sub
    EndClass

    To access the same class, I designed a small form with four text boxes (for empno, ename, sal and deptno) and a few buttons.  The code for the button “search” is given below:

    PrivateSub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
            Dim ep As New Emp
            ep.load(Me.txtEmpno.Text)
            Me.txtDeptno.Text = ep.m_deptno
            Me.txtEname.Text = ep.m_ename
            Me.txtSal.Text = ep.m_sal
        End Sub

    I shall explain the above code in the next section.

    More Visual Basic.NET Articles
    More By Jagadish Chaterjee


       · Hello guys. This series introduces you the OOPS in VB 2005. enjoy
       · I am unable to download the zip file.
       · The link has been corrected. Thank you for pointing out the link and we apologize...
       · Hello jagdish. i wanna to ask you, being a newbie in vb.net 2005, is this the best...
       · Hai,This series explains you the simplest way to develop OOP based db...
     

    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 4 hosted by Hostway