Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 4 - 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 
Moblin 
JMSL Numerical Library 
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: 5 stars5 stars5 stars5 stars5 stars / 11
    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


    Using Constructors with Object Oriented Database Development with VB.NET 2005 - The complete source code for working with the config file


    (Page 4 of 5 )

    The following is the source code used to work with the "config" file very effectively within a VB.NET application.

    Imports System
    Imports System.Xml.Serialization
    Imports System.IO

    Public Class ApplicationSettings
        Private m_DBConnectionString As String = "type ConnectionString to
    connect to database here"

        Public Property DBConnectionString() As String
            Get
                Return m_DBConnectionString
            End Get
            Set(ByVal Value As String)
                m_DBConnectionString = Value
            End Set
        End Property

        Public Sub SaveAppSettings()
            Dim myWriter As StreamWriter = Nothing
            Dim mySerializer As XmlSerializer = Nothing
            Try
                ' Create an XmlSerializer for the 
                ' ApplicationSettings type.
                mySerializer = New XmlSerializer( _
                  GetType(ApplicationSettings))
                'myWriter = New StreamWriter(Application.LocalUserAppDataPath
    + "Application.config", False)
                myWriter = New StreamWriter(APPLICATION_SETTINGS_FILEPATH +
    "Application.config", False)
                ' Serialize this instance of the ApplicationSettings 
                ' class to the config file. 
                mySerializer.Serialize(myWriter, Me)
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            Finally
                ' If the FileStream is open, close it.
                If Not (myWriter Is Nothing) Then
                    myWriter.Close()
                End If
            End Try
        End Sub
        Public Function LoadAppSettings() As Boolean
            Dim mySerializer As XmlSerializer = Nothing
            Dim myFileStream As FileStream = Nothing
            Dim fileExists As Boolean = False

            Try
                ' Create an XmlSerializer for the ApplicationSettings type.
                mySerializer = New XmlSerializer(GetType(ApplicationSettings))
                'Dim fi As New FileInfo(Application.LocalUserAppDataPath +
    "Application.config")
                Dim fi As New FileInfo(APPLICATION_SETTINGS_FILEPATH +
    "Application.config")
                ' If the config file exists, open it.
                If fi.Exists Then
                    myFileStream = fi.OpenRead()
                    ' Create a new instance of the ApplicationSettings by
                    ' deserializing the config file. 
                    Dim myAppSettings As ApplicationSettings = CType( _
                      mySerializer.Deserialize(myFileStream), _
                        ApplicationSettings)
                    ' Assign the property values to this instance of 
                    ' the ApplicationSettings class. 
                    Me.DBConnectionString = myAppSettings.DBConnectionString
                    fileExists = True
                End If
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            Finally
                ' If the FileStream is open, close it.
                If Not (myFileStream Is Nothing) Then
                    myFileStream.Close()
                End If
            End Try

            Return fileExists
        End Function

    End Class

    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

    - 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...
    - Creating and Drawing a Game Map in VB.NET (F...
    - 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 ...





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