62,050
社区成员
发帖
与我相关
我的任务
分享
DataRow 和 DataColumn 对象是 DataTable 的主要组件。使用 DataRow 对象及其属性和方法检索、评估、插入、删除和更新 DataTable 中的值。DataRowCollection 表示 DataTable 中的实际 DataRow 对象,DataColumnCollection 中包含用于描述 DataTable 的架构的 DataColumn 对象。使用重载的 Item 属性返回或设置 DataColumn 的值。
使用 HasVersion 和 IsNull 属性确定特定行值的状态,使用 RowState 属性确定行相对于它的父级 DataTable 的状态。
若要创建新的 DataRow,请使用 DataTable 对象的 NewRow 方法。创建新的 DataRow 之后,请使用 Add 方法将新的 DataRow 添加到 DataRowCollection 中。最后,调用 DataTable 对象的 AcceptChanges 方法以确认是否已添加。有关将数据添加到 DataTable 中的更多信息,请参见向数据表中添加数据。
您可通过调用 DataRowCollection 的 Remove 方法或调用 DataRow 对象的 Delete 方法,从 DataRowCollection 中删除 DataRow。Remove 方法将行从集合中移除。与此相反,Delete 标记要移除的 DataRow。在调用 AcceptChanges 方法时发生实际移除。通过调用 Delete,您可在实际删除行之前以编程方式检查哪些行被标记为移除。有关更多信息,请参见 DataRow 删除。