本文整理汇总了C#中System.Data.StateChangeEventArgs类的典型用法代码示例。如果您正苦于以下问题:C# StateChangeEventArgs类的具体用法?C# StateChangeEventArgs怎么用?C# StateChangeEventArgs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StateChangeEventArgs类属于System.Data命名空间,在下文中一共展示了StateChangeEventArgs类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnStateChange
// 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";
}