Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 2 - Using Methods with Object Oriented Databas...
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 
Moblin 
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 Methods with 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 / 16
    2006-07-19

    Table of Contents:
  • Using Methods with Object Oriented Database Development with VB.NET 2005
  • Developing methods with parameters having default values
  • Dealing with method overloading to attain more flexibility
  • Developing methods with parameters as objects
  • Developing methods which return objects

  • 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

    Free Web 2.0 Code Generator! Generate data entry 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!

    Using Methods with Object Oriented Database Development with VB.NET 2005 - Developing methods with parameters having default values


    (Page 2 of 5 )

    Sometimes, it may be necessary for one or more parameters of a method to have default values. If the calling program didn't pass any values to the parameters, the default values will be taken into consideration. If the user passes values to the parameters, the default values get replaced with the values sent by the calling program.

    Let us modify the same method listed in the previous section:

    PublicFunction isEmployeeExist(Optional ByVal empno As String = Nothing)
    As Boolean
            Dim cn As New SqlConnection("Data Source=.sql2k5;initial
    catalog=sample;user id=sa;password=eXpress2005"
    )
            If Not empno Is Nothing Then
                m_empno = empno
            End If
            Dim cmd As New SqlCommand("select 'exists' from sample.dbo.emp
    where empno='"
    & m_empno & "'", cn)
            Dim found As Boolean = False
            Try
                cmd.Connection.Open()
                Dim rd As SqlDataReader = cmd.ExecuteReader
                If rd.Read() Then
                    found = True
                End If
            Catch ex As Exception
                Throw New Exception(ex.Message)
            Finally
                If cmd.Connection.State = ConnectionState.Open Then
                    cmd.Connection.Close()
                End If
                cmd.Dispose()
                cn.Dispose()
            End Try
            Return found
        End Function

    From the method above, you can understand that the parameter is mentioned as optional. Currently, I assigned the default value for the "empno" as "nothing." If the calling program doesn't pass any value to this method, it takes "m_empno" as the value to search. To execute the above method, you can work with the same code available in the previous section, or you can further modify it as follows:

    PrivateSub btnSearch_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles btnSearch.Click
            Me.lblErrMsg.Text = ""
            Try
                Dim ep As New Emp
                ep.m_empno = Me.txtEmpno.Text
                If ep.isEmployeeExist() Then
                    ep.load(Me.txtEmpno.Text)
                    Me.txtDeptno.Text = ep.m_deptno
                    Me.txtEname.Text = ep.m_ename
                    Me.txtSal.Text = ep.m_sal
                Else
                    Throw New Exception("Employee not found")
                End If
            Catch ex As Exception
                Me.lblErrMsg.Text = ex.Message
            End Try
        End Sub

    More Visual Basic.NET Articles
    More By Jagadish Chaterjee


       · Hello guys! this is my next contribution on database oriented OOPS with VB.NET 2005....
     

    VISUAL BASIC.NET ARTICLES

    - Movement and Player Statistics in a VB.NET T...
    - 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...





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