本文整理汇总了C#中System.Data.DataRowView类的典型用法代码示例。如果您正苦于以下问题:C# DataRowView类的具体用法?C# DataRowView怎么用?C# DataRowView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataRowView类属于System.Data命名空间,在下文中一共展示了DataRowView类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: DemonstrateRowVersion
private static void DemonstrateRowVersion()
{
// Create a DataTable with one column.
DataTable table = new DataTable("Table");
DataColumn column = new DataColumn("Column");
table.Columns.Add(column);
// Add ten rows.
DataRow row;
for (int i = 0; i < 10; i++)
{
row = table.NewRow();
row["Column"] = "item " + i;
table.Rows.Add(row);
}
table.AcceptChanges();
// Create a DataView with the table.
DataView view = new DataView(table);
// Change one row's value:
table.Rows[1]["Column"] = "Hello";
// Add one row:
row = table.NewRow();
row["Column"] = "World";
table.Rows.Add(row);
// Set the RowStateFilter to display only added
// and modified rows.
view.RowStateFilter = DataViewRowState.Added |
DataViewRowState.ModifiedCurrent;
// Print those rows. Output includes "Hello" and "World".
PrintView(view, "ModifiedCurrent and Added");
// Set filter to display only originals of modified rows.
view.RowStateFilter = DataViewRowState.ModifiedOriginal;
PrintView(view, "ModifiedOriginal");
// Delete three rows.
table.Rows[1].Delete();
table.Rows[2].Delete();
table.Rows[3].Delete();
// Set the RowStateFilter to display only deleted rows.
view.RowStateFilter = DataViewRowState.Deleted;
PrintView(view, "Deleted");
// Set filter to display only current rows.
view.RowStateFilter = DataViewRowState.CurrentRows;
PrintView(view, "Current");
// Set filter to display only unchanged rows.
view.RowStateFilter = DataViewRowState.Unchanged;
PrintView(view, "Unchanged");
// Set filter to display only original rows.
// Current values of unmodified rows are also returned.
view.RowStateFilter = DataViewRowState.OriginalRows;
PrintView(view, "OriginalRows");
}
private static void PrintView(DataView view, string label)
{
Console.WriteLine("\n" + label);
for (int i = 0; i < view.Count; i++)
{
Console.WriteLine(view[i]["Column"]);
Console.WriteLine("DataViewRow.RowVersion: {0}",
view[i].RowVersion);
}
}
开发者ID:.NET开发者,项目名称:System.Data,代码行数:73,代码来源:DataRowView
注:本文中的System.Data.DataRowView类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论