• DataRowState


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data;

    namespace DataRowState_Demo
    {
        
    class Program
        {
            
    static void Main(string[] args)
            {
                DemonstrateRowState();
            }

            
    static private void DemonstrateRowState()
            {
                
    // 创建一个仅有一列的空表
                DataTable dataTable = new DataTable("dataTable");
                DataColumn dataColumn 
    = new DataColumn("dataColumn");
                dataTable.Columns.Add(dataColumn);

                
    // 添加十行记录item 0,item 1,item 2,,item 9
                DataRow dataRow;
                
    for (int i = 0; i < 10; i++)
                {
                    dataRow 
    = dataTable.NewRow();
                    dataRow[
    "dataColumn"= "item " + i;
                    dataTable.Rows.Add(dataRow);
                }
                
    //标记接收数据变化
                dataTable.AcceptChanges();

                
    // 创建数据表视图
                DataView dataView = new DataView(dataTable);

                
    // 改变一个行值
                dataTable.Rows[1]["dataColumn"= "Hello";

                
    // Add one row:
                dataRow = dataTable.NewRow();
                dataRow[
    "dataColumn"= "World";
                dataTable.Rows.Add(dataRow);

                
    // 设置行过滤,仅显示新增的和当前改变的
                dataView.RowStateFilter = DataViewRowState.Added
                    
    | DataViewRowState.ModifiedCurrent;

                
    // 输出行为 "Hello" "World"
                PrintView(dataView, "ModifiedCurrent and Added");

                
    // 设置过滤显示被修改行的原始值
                dataView.RowStateFilter = DataViewRowState.ModifiedOriginal;
                PrintView(dataView, 
    "ModifiedOriginal");

                
    // 删除3行
                dataTable.Rows[1].Delete();
                dataTable.Rows[
    2].Delete();
                dataTable.Rows[
    3].Delete();

                
    // 设置行过滤显示只显示和修改 
                dataView.RowStateFilter = DataViewRowState.Deleted;
                PrintView(dataView, 
    "Deleted");

                
    //显示当前数据
                dataView.RowStateFilter = DataViewRowState.CurrentRows;
                PrintView(dataView, 
    "Current");

                
    //显示没有改变的行
                dataView.RowStateFilter = DataViewRowState.Unchanged;
                PrintView(dataView, 
    "Unchanged");

                
    //显示原始数据.
                dataView.RowStateFilter = DataViewRowState.OriginalRows;
                PrintView(dataView, 
    "OriginalRows");
            }

            
    static private void PrintView(DataView dataView, string label)
            {
                Console.WriteLine(
    " " + label + "---------------");
                
    for (int i = 0; i < dataView.Count; i++)
                {
                    Console.WriteLine(dataView[i][
    "dataColumn"]);
                }
            }
        }
    }
  • 相关阅读:
    微信小程序Java登录流程(ssm实现具体功能和加解密隐私信息问题解决方案)
    微信公众号支付开发全过程(java版)
    java实现沙箱测试环境支付宝支付(demo)和整合微信支付和支付宝支付到springmvc+spring+mybatis环境全过程(支付宝和微信支付、附源码)
    自己动手写一个单链表
    设计模式——开发常用的设计模式梳理
    Hexo+github搭建个人博客-博客发布篇
    Hexo+github搭建个人博客-博客初始化篇
    Hexo+github搭建个人博客-环境搭建篇
    git使用说明
    Eclipse快捷键
  • 原文地址:https://www.cnblogs.com/RobotTech/p/1363103.html
Copyright © 2020-2023  润新知