DataTable Class

Overview

The DataTable class is the concrete implementation of IDataTable in the POCO DataSet framework. It represents a single table of data, including its schema (columns), rows, table name, and primary key definition.

A DataTable owns its rows and is responsible for attaching rows, initializing missing column values, and managing row state transitions when rows are added or loaded from persistent storage.

Namespace and Assembly

Namespace: PocoDataSet.Data
Assembly: PocoDataSet.Data.dll

Declaration

public class DataTable : IDataTable
{
    public List<IColumnMetadata> Columns { get; set; }
    public IReadOnlyList<IDataRow> Rows { get; }
    public List<IDataRow> RowsJson { get; }
    public List<string> PrimaryKeys { get; set; }
    public string TableName { get; set; }

    public void AddLoadedRow(IDataRow dataRow);
    public void AddRow(IDataRow dataRow);
    public bool ContainsRow(IDataRow dataRow);
    public void RemoveAllRows();
    public bool RemoveRow(IDataRow dataRow);
    public void RemoveRowAt(int rowIndex);
}

Usage Notes

Usage Example

// 1. Create an empty data set and table
IDataSet dataSet = DataSetFactory.CreateDataSet();
IDataTable departmentDataTable = dataSet.AddNewTable("Department");
departmentDataTable.AddColumn("Id", DataTypeNames.INT32);
departmentDataTable.AddColumn("Name", DataTypeNames.STRING);
departmentDataTable.PrimaryKeys.Add("Id");

// 2. Add a new client-side row
IDataRow row = departmentDataTable.AddNewRow();
row["Name"] = "Emergency";

// 3. Accept changes to normalize the row state for this new row
row.AcceptChanges();

// 4. Remove all rows from the table
departmentDataTable.RemoveAllRows();

 

 

Table of Content POCO DataSet PocoDataSet.Data

 


Business Process Programming in .Net
© 2004–2026 Laskarzhevsky Software Inc.
Unless otherwise noted, the content of this website is licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0).
Code examples are provided under the MIT License.
You are free to share and adapt the material provided that appropriate credit is given and any modifications are clearly indicated.
The information provided on this website is for educational purposes only.
The author and publisher make no warranties regarding the completeness or suitability of the information and are not responsible for any damages resulting from its use.