StateChangeEventArgs 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
提供 .NET 数据提供程序的状态更改事件数据。
public ref class StateChangeEventArgs sealed : EventArgs
public sealed class StateChangeEventArgs : EventArgs
type StateChangeEventArgs = class
inherit EventArgs
Public NotInheritable Class StateChangeEventArgs
Inherits EventArgs
- 继承
示例
以下示例演示如何 StateChange
在 类中使用 SqlConnection 事件。
// 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
注解
数据由 StateChange
的 OleDbConnection 属性和 StateChange
的 SqlConnection属性使用。
构造函数
StateChangeEventArgs(ConnectionState, ConnectionState) |
在给定对象的原始状态和当前状态的情况下,初始化 StateChangeEventArgs 类的新实例。 |
属性
CurrentState |
获取连接的新状态。 在激发该事件时,连接对象将处于新状态。 |
OriginalState |
获取连接的原始状态。 |
方法
Equals(Object) |
确定指定对象是否等于当前对象。 (继承自 Object) |
GetHashCode() |
作为默认哈希函数。 (继承自 Object) |
GetType() |
获取当前实例的 Type。 (继承自 Object) |
MemberwiseClone() |
创建当前 Object 的浅表副本。 (继承自 Object) |
ToString() |
返回表示当前对象的字符串。 (继承自 Object) |