当前位置: 首页>>代码示例>>C#>>正文


C# DataSet.GetChanges方法代码示例

本文整理汇总了C#中DataSet.GetChanges方法的典型用法代码示例。如果您正苦于以下问题:C# DataSet.GetChanges方法的具体用法?C# DataSet.GetChanges怎么用?C# DataSet.GetChanges使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataSet的用法示例。


在下文中一共展示了DataSet.GetChanges方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetChanges_ByDataRowState

        public void GetChanges_ByDataRowState()
        {
            var ds = new DataSet();
            object[] arrAdded, arrDeleted, arrModified, arrUnchanged;
            //object[] arrDetached;

            DataRow dr;
            ds.Tables.Add(DataProvider.CreateParentDataTable());

            // GetChanges 1
            Assert.Equal(null, ds.GetChanges());

            //make some changes

            // can't check detached
            //		dr = ds.Tables[0].Rows[0];
            //		arrDetached = dr.ItemArray;
            //		dr.Delete();
            //		ds.Tables[0].AcceptChanges();

            dr = ds.Tables[0].Rows[1];
            arrDeleted = dr.ItemArray;
            dr.Delete();

            dr = ds.Tables[0].Rows[2];
            dr[1] = "NewValue";
            arrModified = dr.ItemArray;

            dr = ds.Tables[0].Select("", "", DataViewRowState.Unchanged)[0];
            arrUnchanged = dr.ItemArray;

            dr = ds.Tables[0].NewRow();
            dr[0] = 1;
            ds.Tables[0].Rows.Add(dr);
            arrAdded = dr.ItemArray;

            // GetChanges Added
            Assert.Equal(arrAdded, ds.GetChanges(DataRowState.Added).Tables[0].Rows[0].ItemArray);

            // GetChanges Deleted
            dr = ds.GetChanges(DataRowState.Deleted).Tables[0].Rows[0];
            object[] tmp = new object[] { dr[0, DataRowVersion.Original], dr[1, DataRowVersion.Original], dr[2, DataRowVersion.Original], dr[3, DataRowVersion.Original], dr[4, DataRowVersion.Original], dr[5, DataRowVersion.Original] };
            Assert.Equal(arrDeleted, tmp);

            //	can't check it	
            //		// GetChanges Detached
            //		dr = ds.GetChanges(DataRowState.Detached).Tables[0].Rows[0];
            //		object[] tmp = new object[] {dr[0,DataRowVersion.Original],dr[1,DataRowVersion.Original],dr[2,DataRowVersion.Original]};
            //		Assert.Equal(arrDetached, tmp);

            // GetChanges Modified
            Assert.Equal(arrModified, ds.GetChanges(DataRowState.Modified).Tables[0].Rows[0].ItemArray);

            // GetChanges Unchanged
            Assert.Equal(arrUnchanged, ds.GetChanges(DataRowState.Unchanged).Tables[0].Rows[0].ItemArray);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:56,代码来源:DataSetTest2.cs

示例2: 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]);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:45,代码来源:DataSetTest.cs

示例3: GetChanges

        public void GetChanges()
        {
            var ds = new DataSet();
            ds.Tables.Add(DataProvider.CreateParentDataTable());

            // GetChanges 1
            Assert.Equal(null, ds.GetChanges());

            DataRow dr = ds.Tables[0].NewRow();
            dr[0] = 9;
            ds.Tables[0].Rows.Add(dr);

            // GetChanges 2
            Assert.Equal(true, ds.GetChanges() != null);

            // GetChanges 3
            Assert.Equal(dr.ItemArray, ds.GetChanges().Tables[0].Rows[0].ItemArray);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:18,代码来源:DataSetTest2.cs


注:本文中的DataSet.GetChanges方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。