StateChangeEventArgs-Klasse
Stellt Daten für das Zustandsänderungsereignis eines .NET Framework-Datenproviders bereit.
Namespace: System.Data
Assembly: System.Data (in system.data.dll)
Syntax
'Declaration
Public NotInheritable Class StateChangeEventArgs
Inherits EventArgs
'Usage
Dim instance As StateChangeEventArgs
public sealed class StateChangeEventArgs : EventArgs
public ref class StateChangeEventArgs sealed : public EventArgs
public final class StateChangeEventArgs extends EventArgs
public final class StateChangeEventArgs extends EventArgs
Hinweise
Die Daten werden von der StateChange -Eigenschaft der OleDbConnection-Klasse und der StateChange -Eigenschaft der SqlConnection-Klasse verwendet.
Beispiel
Im folgenden Beispiel wird die Verwendung des StateChange -Ereignisses in der SqlConnection-Klasse veranschaulicht.
' 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
// 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";
}
Vererbungshierarchie
System.Object
System.EventArgs
System.Data.StateChangeEventArgs
Threadsicherheit
Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
.NET Compact Framework
Unterstützt in: 2.0, 1.0