Visual Basic.NET
  Home arrow Visual Basic.NET arrow 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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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 / 19
    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


    Using Methods with Object Oriented Database Development with VB.NET 2005


    (Page 1 of 5 )

    This is the second article in a series on developing object oriented database applications using Visual Basic.NET 2005. In this article, I shall deal with the concept of “methods” a bit more in depth, along with data access.
    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 gives you the basics of OOP along with database development, I shall extend it in the form of a series to cover most advanced topics in Visual Basic.NET 2005.  If you are very new to OOP in VB.NET, I request that you go through my first article in this series.

    The entire source code for this article is available 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 methods which return Boolean values

    In my previous article, I introduced classes, members, fields, methods and objects.  Now, in this article, we shall look a bit more in depth into classes and methods.

    The following is a new method I added to the class "Emp:"

    PublicFunction isEmployeeExist(ByVal empno As String) As Boolean
            Dim cn As New SqlConnection("Data Source=.sql2k5;initial
    catalog=sample;user id=sa;password=eXpress2005"
    )
            Dim cmd As New SqlCommand("select 'exists' from sample.dbo.emp
    where empno='"
    & empno & "'", cn)
            Dim found As Boolean = False
            Try
                m_empno = empno
                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

    The above method can be considered to be a "method returning a value." In this case, we are returning a Boolean value. To execute the above method, I modified the "btnSearch_click" 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
                If ep.isEmployeeExist(Me.txtEmpno.Text) 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

    - User-defined Functions using Visual Basic Ap...
    - Understanding Object Binding in VBA
    - Mastering the Message Box
    - Testing a Windows Forms Application
    - Using Visual Basic.NET Features to Code a Wi...
    - Correcting Code in a Windows Forms Applicati...
    - Write Readable Code and Comments for Windows...
    - How to Code and Test a Windows Forms Applica...
    - Adding Features to a Windows Forms Applicati...
    - How to Design a Windows Forms Application
    - LINQ to XML Programming Using Visual Basic.N...
    - Understanding Delegates using Visual Basic.N...
    - Create a Sudoku Puzzle Generator using VB.NET
    - Entity Creation and Messaging in a VB.NET Te...
    - Movement and Player Statistics in a VB.NET T...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek