Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 4 - Properties and Object Oriented Database De...
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

Properties and 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 / 21
    2006-07-26

    Table of Contents:
  • Properties and Object Oriented Database Development with VB.NET 2005
  • The class “Emp” rewritten with properties
  • Accessing the object properties from the form
  • Using read-only properties to deal with error messages

  • 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


    Properties and Object Oriented Database Development with VB.NET 2005 - Using read-only properties to deal with error messages


    (Page 4 of 4 )

    I already covered read-only properties in the previous section. There exists one more situation where you can use read-only properties flexibly. In my first article, I explained exception handling. Now, I can use exception handling and provide the error messages using a read-only property!

    Let us go through the following code first:

    Public Class Emp
         
    ...
        Private m_errMsg As String
          ...
        Public Sub delete(ByVal empno As String)
            m_errMsg = ""
            Dim cn As New SqlConnection("Data Source=.sql2k5;initial catalog=sample;user id=sa;password=eXpress2005")
            Dim cmd As New SqlCommand
            Try
                With cmd
                    .CommandText = "delete from sample.dbo.emp where empno='" & empno & "'"
                    .Connection = cn
                    .Connection.Open()
                    .ExecuteNonQuery()
                End With
            Catch ex As Exception
                m_errMsg = ex.Message
            Finally
                If cmd.Connection.State = ConnectionState.Open Then
                    cmd.Connection.Close()
                End If
                cmd.Dispose()
                cn.Dispose()
            End Try
        End Sub

        Public ReadOnly Property ErrorMessages() As String
            Get
                Return m_errMsg
            End Get
        End Property
    End Class

    You can observe that I included a separate field to hold error messages. When any exception/error is generated within the method “delete,” the error message is stored in “m_errMsg.” You can check/retrieve the error messages using a read-only property called “ErrorMessages.” The above is simply an example to let you know about other possibilities. You should double check as to whether you really need this type of logic to be implemented in your application.

    In this article, I simply wanted to explain the topics of OOPS along with data access.  The sample codes given in this article are neither the best in performance nor the best in programming methodologies.  My upcoming articles will deal with these aspects.

    Any feedback, suggestions, bugs, errors, improvements etc., are highly appreciated at jag_chat@yahoo.com.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Hello guys. Now you can dip into developing properties in Visual Basic.NET....
     

    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 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek