SunQuest
 
       Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 5 - 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 
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 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 - Developing a simple Data Helper


    (Page 5 of 5 )

    Retrieving a single row

    In general, when we develop any application, we frequently work with getting single or multiple rows, execute SQL statements, and so forth. It is always better to have at least a simple Data Helper to improve productivity.

    A sample Data Helper method to retrieve a single row would be as follows:

    ImportsSystem.Data.SqlClient
    PublicClass DataHelper
        Public Shared Function getDataRow(ByVal sqlSELECT As String) As
    System.Data.DataRow
            Dim ConnAs SqlConnection

            Dim da As SqlDataAdapter
            Try
                Conn= New SqlConnection(DB_CONNECTIONSTRING)

                Dim dt As New DataTable
                da = New SqlDataAdapter(sqlSELECT, Conn)
                da.Fill(dt)
                da.Dispose()
                If dt.Rows.Count = 0 Then
                    Return Nothing
                Else
                    Dim dr As DataRow = dt.Rows(0) 'return only first row
                    Return dr
                End If
            Catch ex As Exception
                
                Try
                    da.Dispose()
                Catch e As Exception
                    'do nothing...if still error persists
                End Try
                Throw New Exception(ex.Message)
            End Try
        End Function

    End
    Class

    Retrieving multiple rows

    In the previous section, I provided a method for retrieving a single row only. In this section, I shall provide another method which retrieves multiple rows.

        Public Shared Function getDataTable(ByVal sqlSELECT As String) As
    System.Data.DataTable
            Dim Conn As SqlConnection
            Dim da As SqlDataAdapter
            Try
                Conn= New SqlConnection(DB_CONNECTIONSTRING)
                Dim dt As New DataTable

                da = New SqlDataAdapter(sqlSELECT,
    Conn)
                da.Fill(dt)
                da.Dispose()
                Return dt

            Catch ex As Exception
                Try
                    da.Dispose()
                Catch e As Exception
                    'do nothing...if still error persists
                End Try
                Throw New Exception(ex.Message)
            End Try
        End Function

    To retrieve only a single value, you can use something like the following:

        Public Shared Function getRowValue(ByVal sqlSELECT As String) As
    String
            Dim Conn As SqlConnection
            Dim cmd As SqlCommand
            Dim value As String = ""
            Try
                Conn= New SqlConnection(DB_CONNECTIONSTRING)

                cmd = New SqlCommand(sqlSELECT,
    Conn)
                With cmd
                    .Connection.Open()
                    value = .ExecuteScalar() & "" 'concatenating an empty
    string..to eliminate null or nothing
                    .Connection.Close()
                    .Dispose()
                End With
                Return value
            Catch ex As Exception
                Try
                    If cmd.Connection.State = ConnectionState.Open Then
                        cmd.Connection.Close()
                        cmd.Dispose()
                    End If
                Catch e As Exception
                    'do nothing...if still error persists
                End Try
                Throw New Exception(ex.Message)
            End Try
        End Function

    In this article, I simply wanted to explain some topics related to 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 issues.

    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 it is the time for constructors in OO DB development with vb.net...
     

    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