c# 如何将datatable的rowstate值改为不是unchanged
1个回答
2014-01-18 · 知道合伙人数码行家
关注
展开全部
RowState 的值取决于两个因素:已对该行执行的操作的类型,以及是否已对 DataRow 调用了 AcceptChanges。
示例代码:
private void DemonstrateRowState()
{
// Run a function to create a DataTable with one column.
DataTable table = MakeTable();
DataRow row;
// Create a new DataRow.
row = table.NewRow();
// Detached row.
Console.WriteLine("New Row " + row.RowState);
table.Rows.Add(row);
// New row.
Console.WriteLine("AddRow " + row.RowState);
table.AcceptChanges();
// Unchanged row.
Console.WriteLine("AcceptChanges " + row.RowState);
row["FirstName"] = "Scott";
// Modified row.
Console.WriteLine("Modified " + row.RowState);
row.Delete();
// Deleted row.
Console.WriteLine("Deleted " + row.RowState);
}
private DataTable MakeTable()
{
// Make a simple table with one column.
DataTable table = new DataTable("table");
DataColumn dcFirstName = new DataColumn(
"FirstName", Type.GetType("System.String"));
table.Columns.Add(dcFirstName);
return table;
}
参考MSDN文章:http://msdn.microsoft.com/zh-cn/library/system.data.datarow.rowstate
示例代码:
private void DemonstrateRowState()
{
// Run a function to create a DataTable with one column.
DataTable table = MakeTable();
DataRow row;
// Create a new DataRow.
row = table.NewRow();
// Detached row.
Console.WriteLine("New Row " + row.RowState);
table.Rows.Add(row);
// New row.
Console.WriteLine("AddRow " + row.RowState);
table.AcceptChanges();
// Unchanged row.
Console.WriteLine("AcceptChanges " + row.RowState);
row["FirstName"] = "Scott";
// Modified row.
Console.WriteLine("Modified " + row.RowState);
row.Delete();
// Deleted row.
Console.WriteLine("Deleted " + row.RowState);
}
private DataTable MakeTable()
{
// Make a simple table with one column.
DataTable table = new DataTable("table");
DataColumn dcFirstName = new DataColumn(
"FirstName", Type.GetType("System.String"));
table.Columns.Add(dcFirstName);
return table;
}
参考MSDN文章:http://msdn.microsoft.com/zh-cn/library/system.data.datarow.rowstate
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询