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


C# DataView.Delete方法代码示例

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


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

示例1: AllowDelete

        public void AllowDelete()
        {
            DataTable dt = DataProvider.CreateParentDataTable();
            DataView dv = new DataView(dt);

            // AllowDelete - default value
            Assert.Equal(true, dv.AllowDelete);

            // AllowDelete - true
            dv.AllowDelete = true;
            Assert.Equal(true, dv.AllowDelete);

            // AllowDelete - false
            dv.AllowDelete = false;
            Assert.Equal(false, dv.AllowDelete);

            dv.AllowDelete = false;
            // AllowDelete false- Exception
            Assert.Throws<DataException>(() =>
            {
                dv.Delete(0);
            });

            dv.AllowDelete = true;
            int RowsCount = dv.Count;
            // AllowDelete true- Exception
            dv.Delete(0);
            Assert.Equal(RowsCount - 1, dv.Count);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:29,代码来源:DataViewTest2.cs

示例2: TestDeleteAndCount

        public void TestDeleteAndCount()
        {
            DataSet dataset = new DataSet("new");
            DataTable dt = new DataTable("table1");
            dataset.Tables.Add(dt);
            dt.Columns.Add("col1");
            dt.Columns.Add("col2");
            dt.Rows.Add(new object[] { 1, 1 });
            dt.Rows.Add(new object[] { 1, 2 });
            dt.Rows.Add(new object[] { 1, 3 });

            DataView dataView = new DataView(dataset.Tables[0]);

            Assert.Equal(3, dataView.Count);
            dataView.AllowDelete = true;

            // Deleting the first row
            dataView.Delete(0);

            Assert.Equal(2, dataView.Count);
        }
开发者ID:ericeil,项目名称:corefx,代码行数:21,代码来源:DataViewTest.cs

示例3: Delete

        public void Delete()
        {
            //create the source datatable
            DataTable dt = DataProvider.CreateChildDataTable();

            //create the dataview for the table
            DataView dv = new DataView(dt);

            int CountView = dv.Count;
            int CountTable = dt.Rows.Count;

            DataRowView drv = dv[0];

            // Delete - DataView Row Count
            dv.Delete(0);
            Assert.Equal(dv.Count, CountView - 1);

            // Delete - Table Row Count 
            Assert.Equal(dt.Rows.Count, CountTable);

            // Delete - check table
            Assert.Equal(dt, drv.Row.Table);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:23,代码来源:DataViewTest2.cs

示例4: TestDeleteClosed

 public void TestDeleteClosed()
 {
     Assert.Throws<IndexOutOfRangeException>(() =>
     {
         DataView TestView = new DataView(_dataTable);
         TestView.Dispose(); // Close the table
         TestView.Delete(0); // cannot access to item at 0.
     });
 }
开发者ID:ericeil,项目名称:corefx,代码行数:9,代码来源:DataViewTest.cs

示例5: TestDeleteNotAllowed

 public void TestDeleteNotAllowed()
 {
     Assert.Throws<DataException>(() =>
     {
         DataView TestView = new DataView(_dataTable);
         TestView.AllowDelete = false;
         TestView.Delete(0);
     });
 }
开发者ID:ericeil,项目名称:corefx,代码行数:9,代码来源:DataViewTest.cs

示例6: TestDeleteOutOfBounds

 public void TestDeleteOutOfBounds()
 {
     Assert.Throws<IndexOutOfRangeException>(() =>
     {
         DataView TestView = new DataView(_dataTable);
         TestView.Delete(100);
     });
 }
开发者ID:ericeil,项目名称:corefx,代码行数:8,代码来源:DataViewTest.cs

示例7: TestDelete

 public void TestDelete()
 {
     Assert.Throws<DeletedRowInaccessibleException>(() =>
     {
         DataView TestView = new DataView(_dataTable);
         TestView.Delete(0);
         DataRow r = TestView.Table.Rows[0];
         Assert.True(!((string)r["itemId"] == "item 1"));
     });
 }
开发者ID:ericeil,项目名称:corefx,代码行数:10,代码来源:DataViewTest.cs

示例8: RowStateFilter_2

        public void RowStateFilter_2()
        {
            DataSet dataset = new DataSet("new");
            DataTable dt = new DataTable("table1");
            dataset.Tables.Add(dt);
            dt.Columns.Add("col1");
            dt.Columns.Add("col2");
            dt.Rows.Add(new object[] { 1, 1 });
            dt.Rows.Add(new object[] { 1, 2 });
            dt.Rows.Add(new object[] { 1, 3 });
            dataset.AcceptChanges();

            DataView dataView = new DataView(dataset.Tables[0]);

            // 'new'  table in this sample contains 6 records
            dataView.AllowEdit = true;
            dataView.AllowDelete = true;
            string v;

            // Editing the row
            dataView[0]["col1"] = -1;
            dataView.RowStateFilter = DataViewRowState.ModifiedOriginal;
            v = dataView[0][0].ToString();
            Assert.Equal(1, dataView.Count);
            Assert.Equal("1", v);

            // Deleting the row
            dataView.Delete(0);
            dataView.RowStateFilter = DataViewRowState.Deleted;

            v = dataView[0][0].ToString();
            Assert.Equal(1, dataView.Count);
            Assert.Equal("1", v);
        }
开发者ID:ericeil,项目名称:corefx,代码行数:34,代码来源:DataViewTest.cs


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