StateChangeEventArgs StateChangeEventArgs StateChangeEventArgs StateChangeEventArgs Class

Definition

Stellt Daten für das Zustandsänderungsereignis eines .NET Framework-Datenproviders bereit.Provides data for the state change event of a .NET Framework data provider.

public ref class StateChangeEventArgs sealed : EventArgs
public sealed class StateChangeEventArgs : EventArgs
type StateChangeEventArgs = class
    inherit EventArgs
Public NotInheritable Class StateChangeEventArgs
Inherits EventArgs
Vererbung
StateChangeEventArgsStateChangeEventArgsStateChangeEventArgsStateChangeEventArgs

Beispiele

Im folgenden Beispiel wird gezeigt, wie das StateChange -Ereignis innerhalb SqlConnection der-Klasse verwendet wird.The following example shows how to use the StateChange event within the SqlConnection class.

// Handler for OnStateChange event.
protected static void OnStateChange(object sender,
    StateChangeEventArgs e)
{
    PrintEventArgs(e);
}

static void Main()
{
    FillDataSet();
}

static private void FillDataSet()
{
    string connectionString = GetConnectionString();
    string queryString =
        "SELECT ProductID, UnitPrice from dbo.Products;";

    // Create a DataAdapter.
    using (SqlDataAdapter dataAdapter =
               new SqlDataAdapter(queryString, connectionString))
    {

        // Add the handlers.
        dataAdapter.SelectCommand.Connection.StateChange
            += new StateChangeEventHandler(OnStateChange);

        // Create a DataSet.
        DataSet dataSet = new DataSet();

        // Fill the DataSet, which fires several StateChange events.
        dataAdapter.Fill(dataSet, 0, 5, "Table");
    }
}

protected static void PrintEventArgs(StateChangeEventArgs args)
{
    Console.WriteLine("StateChangeEventArgs");
    Console.WriteLine("  OriginalState= {0} CurrentState= {1}",
        args.OriginalState, args.CurrentState);
}

static private string GetConnectionString()
{
    // To avoid storing the connection string in your code, 
    // you can retrieve it from a configuration file.
    return "Data Source=(local);Initial Catalog=Northwind;"
        + "Integrated Security=true";
}
' Handler for the OnStateChange event.
Private Sub OnStateChange(ByVal sender As Object, _
    ByVal e As StateChangeEventArgs)
    PrintEventArgs(e)
End Sub

Sub Main()
    FillDataSet()
End Sub

Private Sub FillDataSet()
    Dim connectionString As String = GetConnectionString()
    Dim queryString As String = _
        "SELECT ProductID, UnitPrice from dbo.Products;"

    ' Create a DataAdapter.
    Using dataAdapter As New SqlDataAdapter( _
        queryString, connectionString)

        ' Add the handlers.
        AddHandler dataAdapter.SelectCommand.Connection.StateChange, _
            AddressOf OnStateChange

        ' Create a DataSet.
        Dim dataSet As New DataSet()

        ' Fill the DataSet, which fires several StateChange events.
        dataAdapter.Fill(dataSet, 0, 5, "Table")
    End Using
End Sub

Private Sub PrintEventArgs(ByVal args As StateChangeEventArgs)
    Console.WriteLine("StateChangeEventArgs")
    Console.WriteLine("  OriginalState= {0} CurrentState= {1}", _
        args.OriginalState, args.CurrentState)
End Sub

Private Function GetConnectionString() As String
    ' To avoid storing the connection string in your code,  
    ' you can retrieve it from a configuration file.
    Return "Data Source=(local);Initial Catalog=Northwind;" _
       & "Integrated Security=true;"
End Function

Hinweise

Die StateChange Daten werden von der OleDbConnection -EigenschaftStateChange der-Eigenschaft und der-Eigenschaft des verwendet. SqlConnectionThe data is used by the StateChange property of the OleDbConnection and the StateChange property of the SqlConnection.

Konstruktoren

StateChangeEventArgs(ConnectionState, ConnectionState) StateChangeEventArgs(ConnectionState, ConnectionState) StateChangeEventArgs(ConnectionState, ConnectionState) StateChangeEventArgs(ConnectionState, ConnectionState)

Initialisiert eine neue Instanz der StateChangeEventArgs-Klasse, wenn der ursprüngliche Zustand und der aktuelle Zustand des Objekts angegeben sind.Initializes a new instance of the StateChangeEventArgs class, when given the original state and the current state of the object.

Eigenschaften

CurrentState CurrentState CurrentState CurrentState

Ruft den neuen Zustand der Verbindung ab.Gets the new state of the connection. Das Verbindungsobjekt weist beim Auslösen des Ereignisses bereits den neuen Zustand auf.The connection object will be in the new state already when the event is fired.

OriginalState OriginalState OriginalState OriginalState

Ruft den ursprünglichen Zustand der Verbindung ab.Gets the original state of the connection.

Methoden

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Bestimmt, ob das angegebene Objekt mit dem aktuellen Objekt identisch ist.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Fungiert als Standardhashfunktion.Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Ruft den Type der aktuellen Instanz ab.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Erstellt eine flache Kopie des aktuellen Object.Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

Gibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt.Returns a string that represents the current object.

(Inherited from Object)

Gilt für: