Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 2 - Using Constructors with Object Oriented Da...
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? 
VISUAL BASIC.NET

Using Constructors with Object Oriented Database Development with VB.NET 2005
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 10
    2006-08-02

    Table of Contents:
  • Using Constructors with Object Oriented Database Development with VB.NET 2005
  • Defining constructors with parameters in a class
  • Constructor overloading within a class
  • The complete source code for working with the config file
  • Developing a simple Data Helper

  • 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

    Using Constructors with Object Oriented Database Development with VB.NET 2005 - Defining constructors with parameters in a class


    (Page 2 of 5 )

    Just like methods in a class, a constructor can also have parameters. This provides a great advantage sometimes when initializing objects with some values. Let us modify the constructor defined in the previous section as follows:

    Public Class Emp


        Private m_empno As String
        Private m_ename As String
        Private m_sal As Double
        Private m_deptno As Integer
        Private m_errMsg As String

    Public
    Sub New(ByVal empno As String, ByVal ename As String, ByVal sal As
    Double, ByVal deptno As Integer)
            m_empno = empno
            m_ename = ename
            m_sal = sal
            m_deptno = deptno
            m_errMsg = ""
        End Sub
        ...
    End Class

    The above class is defined with a constructor with parameters. In the above case, we cannot simply create an object with the "new" keyword. The declaration of the object should look something like the following:

                Dim ep As New Emp("1001", "jag", 1000, 10)

    The above statement creates and instantiates an object by calling the constructor with parameters. We can rewrite our code for "btnAdd_Click" as follows:

        Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles btnAdd.Click
            Me.lblErrMsg.Text = ""
            Try
                Dim ep As New Emp(Me.txtEmpno.Text, Me.txtEname.Text,
    Me.txtSal.Text, Me.txtDeptno.Text)
                ep.add()
            Catch ex As Exception
                Me.lblErrMsg.Text = ex.Message
            End Try
        End Sub

    More Visual Basic.NET Articles
    More By Jagadish Chaterjee


       · Hello guys. Now it is the time for constructors in OO DB development with vb.net...
     

    VISUAL BASIC.NET ARTICLES

    - Creating and Drawing a Game Map in VB.NET
    - Working with Classes and Properties for Game...
    - Working with Loops, Arrays, and Collections ...
    - Learning Loops in VB.NET for Game Development
    - Learning VB.NET: Working with Variables, Con...
    - The Basics of VB.NET Through Text Game Devel...
    - Learning VB.NET Through Text Game Development
    - 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...





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