ADO.NET对象的构造(5)_DataRow
来源:互联网 发布:matlab怎么用编程语言 编辑:程序博客网 时间:2024/06/12 21:44
DataRow构造
n Protected Friend Sub New(ByVal builder As DataRowbuilderclasstopic.htm">DataRowBuilder)
DataRow 和 DataColumn 对象是 DataTable 的主要组件。使用 DataRow 对象及其属性和方法检索、评估、插入、删除和更新 DataTable 中的值。DataRowcollectionclasstopic.htm">DataRowCollection 表示 DataTable 中的实际 DataRow 对象,DataColumnCollection 中包含用于描述 DataTable 的架构的 DataColumn 对象。使用重载的 DataRowclassitemtopic.htm">Item 属性返回或设置 DataColumn 的值。
使用 DataRowclasshasversiontopic.htm">HasVersion 和 DataRowclassisnulltopic.htm">IsNull 属性确定特定行值的状态,使用 DataRowclassrowstatetopic.htm">RowState 属性确定行相对于它的父级 DataTable 的状态。
若要创建新的 DataRow,请使用 DataTable 对象的 NewRow 方法。创建新的 DataRow 之后,请使用 DataRowcollectionclassaddtopic.htm">Add 方法将新的 DataRow 添加到 DataRowCollection 中。最后,调用 DataTable 对象的 DataRowclassacceptchangestopic.htm">AcceptChanges 方法以确认是否已添加。
您可通过调用 DataRowCollection 的 DataRowcollectionclassremovetopic.htm">Remove 方法或调用 DataRow 对象的 DataRowclassdeletetopic.htm">Delete 方法,从 DataRowCollection 中删除 DataRow。Remove 方法将行从集合中移除。与此相反,Delete 标记要移除的 DataRow。在调用 AcceptChanges 方法时发生实际移除。通过调用 Delete,您可在实际删除行之前以编程方式检查哪些行被标记为移除。
DataRow的两个重要方法
n HasVersion方法
Public Function HasVersion(ByVal version As DataRowversionclasstopic.htm">DataRowVersion) As Boolean
参数
1. version DataRowversionclasstopic.htm">DataRowVersion 值之一,它指定行版本。
当使用 DataRowclassitemtopic.htm">Item 或 DataRowclasstopic.htm">DataRow 对象的 DataRowclassgetchildrowstopic.htm">GetChildRows 检索在 DataRow 中找到的值时,使用 DataRowVersion 值。
DataRowVersion 向您通知存在 DataRow 的哪个版本。版本在以下情况下发生更改:
n 在调用 DataRowclasstopic.htm">DataRow 对象的 DataRowclassbeginedittopic.htm">BeginEdit 方法之后,如果更改该值,则 Current 和 Proposed 值变得可用。
n 在调用 DataRowclasstopic.htm">DataRow 对象的 DataRowclasscanceledittopic.htm">CancelEdit 方法之后,Proposed 值将被删除。
n 在调用 DataRowclasstopic.htm">DataRow 对象的 DataRowclassendedittopic.htm">EndEdit 方法之后,Proposed 值变成 Current 值。
n 在调用 DataRowclasstopic.htm">DataRow 对象的 DataRowclassacceptchangestopic.htm">AcceptChanges 方法之后,Original 值变得与 Current 值相同。
n 在调用 DataTable 对象的 AcceptChanges 方法之后,Original 值变得与 Current 值相同。
n 在调用 DataRowclasstopic.htm">DataRow 对象的 DataRowclassrejectchangestopic.htm">RejectChanges 之后,Proposed 值将被丢弃,版本变成 Current。
成员名称
说明
Current
该行中包含当前值。
Default
是 DataRowstateclasstopic.htm">DataRowState 对当前行的默认版本。对于 Added、Modified 或 Current 的 DataRowState 值,默认版本是 Current。对于 Deleted 的 DataRowState,该版本是 Original。对于 Detached 的 DataRowState 值,该版本是 Proposed。
Original
该行中包含其原始值。
Proposed
该行中包含建议值。
示例
以下示例使用 HasVersion 方法确定列的当前值和建议值是否相同。如果相同,则取消编辑。否则,调用 AcceptChanges 方法以终止编辑。
Private Sub CheckVersionBeforeAccept()
Dim r As DataRow
Dim t As DataTable
' Assuming the DataGrid is bound to a DataTable.
t = CType(DataGrid1.DataSource, DataTable)
r = t.Rows(DataGrid1.CurrentCell.RowNumber)
r.BeginEdit
r(1) = Edit1.Text
If r.HasVersion(DataRowversion.Proposed) Then
If r(1, DataRowVersion.Current) Is r(1, DataRowversion.Proposed) Then
MessageBox.Show("The original and the proposed are the same")
r.CancelEdit
Exit Sub
Else
r.AcceptChanges
End If
Else
MessageBox.Show("No new values proposed")
End If
End Sub
- ADO.NET对象的构造(5)_DataRow
- ADO.NET对象的构造(4)_DataColumn
- ADO.NET对象的构造(3)_DataTable
- ADO.NET对象的构造(1)_OleDbDataAdapter
- ADO.NET对象的构造(6)_OleDbCommand
- ADO.NET对象的构造(4)_DataColumn(续)
- ADO.Net的对象模型
- ADO.NET的内置对象
- ADO.NET的对象 一
- ADO.NET的对象二
- ADO.NET对象的应用
- ADO.NET对象的使用
- ADO.NET对象的详解
- ADO.Net 5大对象
- ASP.NET:ADO.NET的Command对象
- [转]ADO.NET的5个主要对象类型
- ADO.NET的Connection对象的使用
- 常用的ADO.NET的五个对象
- 实用生活英语句子 174句
- ADO.NET对象的构造(1)_OleDbDataAdapter
- 关于internationlization
- 精通Silverlight——12.3.2 KyeboardEventArgs参数
- 继续积累:数据库同步(发布与订阅)
- ADO.NET对象的构造(5)_DataRow
- Welcome!
- 品牌中的英语含义
- C#中取拼音码
- Tomcat调试经验。
- 终于搞清楚了如何做非表格的导航条
- ADO.NET对象的构造(4)_DataColumn(续)
- 20种常见的ps技术
- 牛根生简介