StateChangeEventArgs Class
Provides data for the state change event of a .NET Framework data provider.
For a list of all members of this type, see StateChangeEventArgs Members.
System.Object
System.EventArgs
System.Data.StateChangeEventArgs
[Visual Basic] NotInheritable Public Class StateChangeEventArgs Inherits EventArgs [C#] public sealed class StateChangeEventArgs : EventArgs [C++] public __gc __sealed class StateChangeEventArgs : public EventArgs [JScript] public class StateChangeEventArgs extends EventArgs
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Remarks
The data is used by the StateChange property of the OleDbConnection and the StateChange property of the SqlConnection.
Example
[Visual Basic, C#, C++] The following example shows how to use the StateChange event within the SqlConnection class.
[Visual Basic] ' handler for StateChange event Protected Shared Sub OnStateChange(sender As Object, e As StateChangeEventArgs) PrintEventArgs(e) End Sub 'OnStateChange 'Entry point which delegates to C-style main Private Function Public Overloads Shared Sub Main() System.Environment.ExitCode = Main(System.Environment.GetCommandLineArgs()) End Sub Overloads Public Shared Function Main(args() As String) As Integer Const CONNECTION_STRING As String = "Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=mySQLServer" Const SELECT_ALL As String = "select * from Products" ' create DataAdapter Dim rAdapter As New SqlDataAdapter(SELECT_ALL, CONNECTION_STRING) ' add handlers AddHandler rAdapter.SelectCommand.Connection.StateChange, AddressOf OnStateChange ' create dataset Dim rDataSet As New DataSet() ' fill dataset, ' DataAdapter will open connection, load data and restore connection state - close connection. ' as result it fires several StateChange events rAdapter.Fill(rDataSet, 0, 5, "Table") Return 0 End Function 'Main Protected Shared Sub PrintEventArgs(args As StateChangeEventArgs) Console.WriteLine("OnStateChange") Console.WriteLine(" event args: (" & _ "originalState=" & _ args.OriginalState & _ " currentState=" & _ args.CurrentState & _ ")") End Sub 'PrintEventArgs End Class 'Form1 [C#] // handler for StateChange event protected static void OnStateChange(object sender, StateChangeEventArgs e) { PrintEventArgs(e); } public static int Main(String[] args) { const string CONNECTION_STRING = "Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=mySQLServer"; 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 result it fires several StateChange events rAdapter.Fill(rDataSet, 0, 5, "Table"); return 0; } protected static void PrintEventArgs(StateChangeEventArgs args) { Console.WriteLine("OnStateChange"); Console.WriteLine(" event args: ("+ "originalState=" + args.OriginalState + " currentState=" + args.CurrentState +")"); } [C++] // handler for StateChange event protected: static void OnStateChange(Object* /*sender*/, StateChangeEventArgs* e) { PrintEventArgs(e); } public: static void main() { String* CONNECTION_STRING = S"Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=mySQLServer"; String* SELECT_ALL = S"select * from Products"; // create DataAdapter SqlDataAdapter* rAdapter = new SqlDataAdapter(SELECT_ALL, CONNECTION_STRING); // add handlers rAdapter->SelectCommand->Connection->StateChange += new StateChangeEventHandler(0, OnStateChange); // create dataset DataSet* rDataSet = new DataSet(); // fill dataset, // DataAdapter will open connection, load data and restore connection state - close connection. // as result it fires several StateChange events rAdapter->Fill(rDataSet, 0, 5, S"Table"); } protected: static void PrintEventArgs(StateChangeEventArgs* args) { Console::WriteLine(S"OnStateChange"); Console::WriteLine(S" event args: (originalState={0} currentState={1})", __box(args->OriginalState), __box(args->CurrentState)); }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.Data
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework
Assembly: System.Data (in System.Data.dll)