本文整理汇总了C#中DataSet.RejectChanges方法的典型用法代码示例。如果您正苦于以下问题:C# DataSet.RejectChanges方法的具体用法?C# DataSet.RejectChanges怎么用?C# DataSet.RejectChanges使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataSet
的用法示例。
在下文中一共展示了DataSet.RejectChanges方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetChanges_Relations_DifferentRowStatesTest
public void GetChanges_Relations_DifferentRowStatesTest()
{
DataSet ds = new DataSet("ds");
DataTable parent = ds.Tables.Add("parent");
DataTable child = ds.Tables.Add("child");
parent.Columns.Add("id", typeof(int));
parent.Columns.Add("name", typeof(string));
child.Columns.Add("id", typeof(int));
child.Columns.Add("parent", typeof(int));
child.Columns.Add("name", typeof(string));
parent.Rows.Add(new object[] { 1, "mono parent 1" });
parent.Rows.Add(new object[] { 2, "mono parent 2" });
parent.Rows.Add(new object[] { 3, "mono parent 3" });
parent.Rows.Add(new object[] { 4, "mono parent 4" });
parent.AcceptChanges();
child.Rows.Add(new object[] { 1, 1, "mono child 1" });
child.Rows.Add(new object[] { 2, 2, "mono child 2" });
child.Rows.Add(new object[] { 3, 3, "mono child 3" });
child.AcceptChanges();
DataRelation relation = ds.Relations.Add("parent_child",
parent.Columns["id"],
child.Columns["parent"]);
// modify the parent and get changes
child.Rows[1]["parent"] = 4;
DataSet changes = ds.GetChanges();
DataRow row = changes.Tables["parent"].Rows[0];
Assert.Equal((int)parent.Rows[3][0], (int)row[0]);
Assert.Equal(1, changes.Tables["parent"].Rows.Count);
ds.RejectChanges();
// delete a child row and get changes.
child.Rows[0].Delete();
changes = ds.GetChanges();
Assert.Equal(changes.Tables.Count, 2);
Assert.Equal(1, changes.Tables["parent"].Rows.Count);
Assert.Equal(1, (int)changes.Tables["parent"].Rows[0][0]);
}
示例2: RuleTest
public void RuleTest()
{
DataSet ds = new DataSet("testds");
DataTable parent = ds.Tables.Add("parent");
DataTable child = ds.Tables.Add("child");
parent.Columns.Add("id", typeof(int));
parent.Columns.Add("name", typeof(string));
parent.PrimaryKey = new DataColumn[] { parent.Columns["id"] };
child.Columns.Add("id", typeof(int));
child.Columns.Add("parent", typeof(int));
child.Columns.Add("name", typeof(string));
child.PrimaryKey = new DataColumn[] { child.Columns["id"] };
DataRelation relation = ds.Relations.Add("parent_child",
parent.Columns["id"],
child.Columns["parent"]);
parent.Rows.Add(new object[] { 1, "mono test 1" });
parent.Rows.Add(new object[] { 2, "mono test 2" });
parent.Rows.Add(new object[] { 3, "mono test 3" });
child.Rows.Add(new object[] { 1, 1, "mono child test 1" });
child.Rows.Add(new object[] { 2, 2, "mono child test 2" });
child.Rows.Add(new object[] { 3, 3, "mono child test 3" });
ds.AcceptChanges();
parent.Rows[0]["name"] = "mono changed test 1";
Assert.Equal(DataRowState.Unchanged, parent.Rows[0].GetChildRows(relation)[0].RowState);
ds.RejectChanges();
parent.Rows[0]["id"] = "4";
DataRow childRow = parent.Rows[0].GetChildRows(relation)[0];
Assert.Equal(DataRowState.Modified, childRow.RowState);
Assert.Equal(4, (int)childRow["parent"]);
}
示例3: RejectChanges
public void RejectChanges()
{
DataSet ds1, ds2 = new DataSet();
ds2.Tables.Add(DataProvider.CreateParentDataTable());
ds1 = ds2.Copy();
//create changes
ds2.Tables[0].Rows[0][0] = "70";
ds2.Tables[0].Rows[1].Delete();
ds2.Tables[0].Rows.Add(new object[] { 9, "string1", "string2" });
// RejectChanges
ds2.RejectChanges();
Assert.Equal(ds2.GetXml(), ds1.GetXml());
}