asp.net.ph

StateChangeEventArgs Class

System.Data Namespace


Provides data for the state change event of a .NET data provider.

StateChangeEventArgs Class Members

Collapse   Constructors

Visibility Constructor Parameters
public StateChangeEventArgs ( ConnectionState originalState , ConnectionState currentState )

Collapse   Properties

Visibility Name Value Type Accessibility
public CurrentState ConnectionState [ Get ]
public OriginalState ConnectionState [ Get ]

Remarks

The data is used by the StateChange property of the OleDbConnection and the StateChange property of the SqlConnection.

Example

The following example shows how to use the StateChange event within the SqlConnection class.

// handler for StateChange event
protected static void OnStateChange ( object sender,
     StateChangeEventArgs e ) {
   PrintEventArgs ( e );
}
public static int Main ( String [ ] args ) {
   const string CONNECTION_STRING = 
      "Server = LocalHost;user id = sa;timeout = 30;database = Northwind";
   const string SELECT_ALL = "SELECT * FROM Products";


   // create DataAdapter
   SqlDataAdapter rAdapter = new SqlDataAdapter
      ( SELECT_ALL, CONNECTION_STRING );


   // add handlers
   rAdapter.SelectCommand.Connection.StateChange + =
      new StateChangeEventHandler ( OnStateChange );


   // create dataset
   DataSet rDataSet = new DataSet ( );


   // fill dataset: DataAdapter will open connection, load data and 

   // restore connection state ( close connection ).

   // as a result it fires several StateChange events
   rAdapter.Fill ( rDataSet, 0, 5, "Table" );
   return 0;
}
protected static void PrintEventArgs ( StateChangeEventArgs args ) {
   Response.Write ( "OnStateChange" );
   Response.Write ( " Event args: ( " +
      " originalState = " + args.OriginalState +
      " currentState = " + args.CurrentState + " ) " );
}
  C# VB

Skip Navigation Links



Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph