Database Connection state change event : Collection « Data Structure « VB.Net

VB.Net
1. 2D
2. Application
3. Class
4. Data Structure
5. Database ADO.net
6. Development
7. Event
8. File Directory
9. Generics
10. GUI
11. Language Basics
12. Network Remote
13. Thread
14. Windows System
15. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
VB.Net » Data Structure » CollectionScreenshots 
Database Connection state change event
Database Connection state change event

Imports System
Imports System.Data
Imports System.Data.SqlClient


public class MainClass
   Shared Sub Main()
      Dim thisConnection As New SqlConnection("server=(local)\SQLEXPRESS;" & _
          "integrated security=sspi;database=MyDatabase")

      ' Sql Query
      Dim sql As String = "SELECT FirstName, LastName From Employee"

      ' Create command
      Dim thisCommand As New SqlCommand(sql, thisConnection)

      ' Add second handler to StateChange event
      AddHandler thisConnection.StateChange, AddressOf StateIsChanged

      Try

         ' Open connection and fire two statechange events
         thisConnection.Open()

         ' Create datareader
         Dim thisReader As SqlDataReader = thisCommand.ExecuteReader()

         ' Display rows in event log
         While thisReader.Read()
            Console.WriteLine(thisReader.GetString(0_
               "-" + thisReader.GetString(1))
         End While
      Catch ex As SqlException
         Console.WriteLine(ex.Message)
      Finally
         ' Remove second handler from StateChange event
         RemoveHandler thisConnection.StateChange, AddressOf StateIsChanged

         ' Close connection and fire one StateChange event
         thisConnection.Close()
      End Try
   End Sub
   Shared Private Sub StateIsChanged(ByVal sender As Object, ByVal e As System.Data.StateChangeEventArgs)
      ' Event handler for the StateChange Event
      Console.WriteLine("Entering Second StateChange EventHandler")
      Console.WriteLine("Sender = " + sender.ToString())
      Console.WriteLine("Original State = " + e.OriginalState.ToString())
      Console.WriteLine("Current State = " + e.CurrentState.ToString())
      Console.WriteLine("Exiting Second StateChange EventHandler")
   End Sub

End Class

           
       
Related examples in the same category
1. Store Objects in Collection and retrieveStore Objects in Collection and retrieve
2. Loop through CollectionLoop through Collection
3. For Each loop through a CollectionFor Each loop through a Collection
4. Do While loop through a CollectionDo While loop through a Collection
5. Store Class in a Collection and Retrieve by NameStore Class in a Collection and Retrieve by Name
ww___w_.j___a_v__a2_s__._co___m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.