StateChangeEventArgs 类

为 .NET Framework 数据提供程序的状态更改事件提供数据。

**命名空间:**System.Data
**程序集:**System.Data(在 system.data.dll 中)

语法

声明
Public NotInheritable Class StateChangeEventArgs
    Inherits EventArgs
用法
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

备注

该数据由 OleDbConnectionStateChange 属性和 SqlConnectionStateChange 属性使用。

示例

下面的示例说明如何在 SqlConnection 类内使用 StateChange 事件。

' 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";
}

继承层次结构

System.Object
   System.EventArgs
    System.Data.StateChangeEventArgs

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

StateChangeEventArgs 成员
System.Data 命名空间