MCQs Test!! VB Basic Test !! Essentials of VB !! Creating User Services !! function !! Anatomy !! GK March-2019 !! DATA TYPES IN JAVA !! Classes ,Constructor ,Methods,Inheritance !! Ecology-I !! Biology 2019 !! Gk april 2019 !! Biology (living world) !! Plant anatomy !! CELL STRUCTURES AND FUNCTION !! General biology !! Human physiology !! Data structure !! Ecology-II !! GK TEST !! Reproduction in plants !! Human reproduction !! The ABC of C !! Operating system set1 !! Operating system set2 !! Gk and current affairs !! Animal kingdom !! Number system !! Animal kingdom-II !! Gk TEST-III !! Number series !! Microorganisms !! Interview question in c !! Time and Work !! Percentage !! General history !! Average !! Cells !! Locomotion and Movement !! paging !! Bacteriology !! Page replacement policy !! Secondary memory and Disk scheduling !! Introduction of Nervous System and neurons !! Plant harmones !! Transport and Mineral Nutrition in Plants !! Neurotransmitters !! Modern Indian History !! Photosynthesis in Plants !! Modern Indian History-II !! Plant respiration !! Environment & Biodiversity !! Environment & Biodiversity - II !! Algae, Bryophytes, Pteridophytes !! Area !! Cricket !! Days of the Year (India and the World) !! Plant Pathology - I !! Indian Transport System !! Plant Pathology - II !! Aptitude !! Biology !! Botany !! C language !! Computer Science !! Core Java !! Gate !! GK !! Mysql !! Operating system !! Physics !! VB-Visual Basic !! Zoology


ADO.NET Projects

ADO.NET Project 1

ADO.NET Examples


Handling Connection Events
Previous Home Next

Both the OLE DB and the SQL Server Connection objects provide two events:

  1. StateChange
  2. InfoMessage.
  1. StateChange: The StateChange event fires whenever the state of the Connection object changes. The event passes a StateChangeEventArgs to its handler, which, inturn, has two properties: OriginalState and CurrentState. The possible values for

  2. OriginalState and CurrentState are:

    Connection States Meaning
    Broken TheConnecton is open, but not functional. It maybe closed and reopened
    Closed The Connection is closed
    Connecting The Connection is in the process of connecting, but has not yet been
    Executing Executing the command
    Fetching Retrieving the data
    Open Open the connection

    To display the previous and current Connection states for each of the two Connection objects: Select OleDbConnection1 in the Class Name combobox of the editor and the StateChange event in the Method Name combobox.


    private void oleDbConnection1_StateChange
       (object sender,StateChangeEventArgs e)
    string s;
    s = "The Connection State is changing from " 
                  + e.OriginalState.ToString() +
             " to " + e.CurrentState.ToString();
    private void SqlDbConnection1_StateChange 
      (object sender, StateChangeEventArgs e)
    string s1;
    s1 = "The Connection State is changing from " +
                     e.OriginalState.ToString() +
                 " to " + e.CurrentState.ToString();

    Add the code to connect the event handlers to the:

    ConnectionProperties sub:

    this.oleDbConnection1.StateChange +=
    this.SqlDbConnection1.StateChange += 
       new System.Data.StateChangeEventHandler

    Save and run the program. Change the Connection Type and then click the Test button.

    The application displays two MessageBoxes as the Connection is opened and closed.

  3. InfoMessage: The InfoMessage event is triggered when the data source returns warnings. The information passed to the event handler depends on the Data Provider.

Previous Home Next