zoukankan      html  css  js  c++  java
  • 关于DataRow的RowState和RowVersion

    关于DataRow的RowState和RowVersion

    1)什么是DataRow's RowState and RowVersion?
          DataRow's RowState是数据行的状态,RowVersion是数据行的版本。
       RowState and Row Version are both enum object.
       The codesnap is the following detail:

    DataRowState
    RowVersion

    2) 究竟RowState和RowVersion有什么关系呢?又个有什么用途呢?
      RowState和RowVersion有一个对照关系(或许描述有点不恰当),
      关系如下所示: 

    RowState RowVersion
    Added Current(Default)
    Modified Current(Default)
    Original 
    Unchanged Current(Default)
    Original(Default)
    Detached Proposed(Default)
    Deleted Original (Default)
    For unchanged rowstate, default row version is also Proposed,从下面的例子中,你能看到。
    从上面的表格可以看出,一个数据行有版本的控制,为什么要有这版本控制呢?
    A)用于DataSet和DataTable内部实现,
    B)
    在用DataAdapter跟DB交互时(Call Update(DataSet)),用什么版本赋值。
    当然只是在DBParameter上设置SourceVersion

    DataAdapter
    DBParameter

    3) 在DataTable.Select()和DataView.RowStateFilter区别,
    public DataRow[] Select (
    string filterExpression,
    string sort,
    DataViewRowState recordStates
    )
    Select
    public Object this [
    DataColumn column,
    DataRowVersion version
    ] { get; }
    
    
    public DataViewRowState RowStateFilter { get; set; }
    其实在性能方面,DataView比DataTable好,DataView use index.
    还是回到这个主题上吧,
    DataTable的方法会返回所有的版本的数据行,而DataView仅返回相关的版本。
    请看下面的例子:
     
    
    Example

    当直接访问删除的数据时,要用databview,否则会出错:
    Deleted row information cannot be accessed through the row.
    dataView[i].Row[1,DataRowVersion.Original]
    dataView[i]["name"]
    也不能用dataView[i].Row[1,DataRowVersion.Default],
    对于Unchanged's RowState,如果Call BeginEdit(),没有call EndEdit(),
    运行上面的例子,就知道答案了。

    (4)在ADO.NET 2.0中,DatRow添加了几个新的方法:
    SetAdded()and SetModified()
     
  • 相关阅读:
    Python3 从零单排10_xml&configparser
    Python3 从零单排9_json&pickle&shelve
    Python3 从零单排7_模块&os&sys
    Python3 从零单排6_装饰器&生成器&迭代器
    Python3 从零单排5_内置函数
    python3 从零单排4_函数进阶
    Python3 从零单排2_文件读写&集合
    查看innodb表空间
    如何从innodb的数据字典里恢复表结构
    innodb double write buffer
  • 原文地址:https://www.cnblogs.com/winner/p/1006737.html
Copyright © 2011-2022 走看看