本文整理汇总了C#中System.Data.DataRow.BeginEdit方法的典型用法代码示例。如果您正苦于以下问题:C# DataRow.BeginEdit方法的具体用法?C# DataRow.BeginEdit怎么用?C# DataRow.BeginEdit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.DataRow
的用法示例。
在下文中一共展示了DataRow.BeginEdit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DemonstrateRowBeginEdit
private void DemonstrateRowBeginEdit()
{
DataTable table = new DataTable("table1");
DataColumn column = new
DataColumn("col1",Type.GetType("System.Int32"));
table.RowChanged+=new
DataRowChangeEventHandler(Row_Changed);
table.Columns.Add(column);
// Add a UniqueConstraint to the table.
table.Constraints.Add(new UniqueConstraint(column));
// Add five rows.
DataRow newRow;
for(int i = 0;i<5; i++)
{
// RowChanged event will occur for every addition.
newRow= table.NewRow();
newRow[0]= i;
table.Rows.Add(newRow);
}
// AcceptChanges.
table.AcceptChanges();
// Invoke BeginEdit on each.
Console.WriteLine(
"\n Begin Edit and print original and proposed values \n");
foreach(DataRow row in table.Rows)
{
row.BeginEdit();
row[0]=(int) row[0]+10;
Console.Write("\table Original \table" +
row[0, DataRowVersion.Original]);
Console.Write("\table Proposed \table" +
row[0,DataRowVersion.Proposed] + "\n");
}
Console.WriteLine("\n");
// Accept changes
table.AcceptChanges();
// Change two rows to identical values after invoking BeginEdit.
table.Rows[0].BeginEdit();
table.Rows[1].BeginEdit();
table.Rows[0][0]= 100;
table.Rows[1][0]=100;
try
{
/* Now invoke EndEdit. This will cause the UniqueConstraint
to be enforced.*/
table.Rows[0].EndEdit();
table.Rows[1].EndEdit();
}
catch(Exception e)
{
// Process exception and return.
Console.WriteLine("Exception of type {0} occurred.",
e.GetType());
}
}
private void Row_Changed(object sender,
System.Data.DataRowChangeEventArgs e)
{
DataTable table = (DataTable) sender;
Console.WriteLine("RowChanged " + e.Action.ToString()
+ "\table" + e.Row.ItemArray[0]);
}