AddNewTable Methods

Overview

The AddNewTable methods add a new data table to a data set.

Declarations

/// <summary>
/// Adds new table to data set without columns and without rows
/// </summary>
/// <param name="dataSet">Data set</param>
/// <param name="tableName">Table name</param>
/// <returns>New table</returns>
/// <exception cref="KeyDuplicationException">Exception is thrown if dataset contains a table with specified name already</exception>
public static IDataTable AddNewTable(this IDataSet? dataSet, string tableName)

/// <summary>
/// Adds new table to data set with columns specified inside of list of column metadata but without rows
/// </summary>
/// <param name="dataSet">Data set</param>
/// <param name="tableName">Table name</param>
/// <param name="listOfColumnMetadata">List of column metadata</param>
/// <returns>New table</returns>
/// <exception cref="KeyDuplicationException">Exception is thrown if dataset contains a table with specified name already</exception>
public static IDataTable AddNewTable(this IDataSet? dataSet, string tableName, List<IColumnMetadata> listOfColumnMetadata)

Namespace and Assembly

Namespace: PocoDataSet.Extensions
Assembly: PocoDataSet.Extensions.dll

Usage Examples

Create an empty table and define the schema later:

// 1. Create a new data set
IDataSet dataSet = DataSetFactory.CreateDataSet();

// 2. Add a new table named "Department"
IDataTable departmentDataTable = dataSet.AddNewTable("Department");

// 3. Define columns for the "Department" table after it is added to data set
departmentDataTable.AddColumn("Id", DataTypeNames.INT32);
departmentDataTable.AddColumn("Name", DataTypeNames.STRING);

Create a table with schema in a single call:

// 1. Create a new data set
IDataSet dataSet = DataSetFactory.CreateDataSet();

// 2. Define list of column metadata for the "Employee" table
List<IColumnMetadata> listOfColumnMetadata = new List<IColumnMetadata>();

IColumnMetadata columnMetadata = new ColumnMetadata();
columnMetadata.ColumnName = "Id";
columnMetadata.DataType = DataTypeNames.INT32;
columnMetadata.IsNullable = false;
columnMetadata.IsPrimaryKey = true;
listOfColumnMetadata.Add(columnMetadata);

columnMetadata = new ColumnMetadata();
columnMetadata.ColumnName = "FirstName";
columnMetadata.DataType = DataTypeNames.STRING;
listOfColumnMetadata.Add(columnMetadata);

columnMetadata = new ColumnMetadata();
columnMetadata.ColumnName = "DepartmentId";
columnMetadata.DataType = DataTypeNames.INT32;
columnMetadata.IsNullable = false;
columnMetadata.IsForeignKey = true;
listOfColumnMetadata.Add(columnMetadata);

// 3. Add a new table named "Employee" with defined columns
IDataTable employeeDataTable = dataSet.AddNewTable("Employee", listOfColumnMetadata);

 

Table of Content POCO DataSet DataSet Members

 


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.