AddRow Method

Overview

The AddRow method adds an existing IDataRow instance to a table inside an IDataSet. It is intended for cases where the row must be created and populated before it is inserted into the table.

In typical scenarios, you will use IDataTable.AddNewRow() (or the corresponding extension) which creates a new row, assigns default values, adds it to the table, and returns it to the caller. Use AddRow when you need more control over row construction (for example, creating a row from column metadata, assigning values, and then inserting it).

Declaration

/// <summary>
/// Adds row to table
/// </summary>
/// <param name="dataSet">Data set</param>
/// <param name="tableName">Table name</param>
/// <param name="dataRow">Data row for addition</param>
/// <exception cref="KeyNotFoundException">Exception is thrown if dataset does not contains a table with specified name</exception>
public static void AddRow(this IDataSet? dataSet, string tableName, IDataRow dataRow)

Namespace and Assembly

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

Behavior

Usage Example

Create a row first, assign values, and then add it to the table:

// 1. Create an empty data set
IDataSet dataSet = DataSetFactory.CreateDataSet();

// 2. Create an empty data table
IDataTable departmentDataTable = dataSet.AddNewTable("Department");
departmentDataTable.AddColumn("Id", DataTypeNames.INT32);
departmentDataTable.AddColumn("Name", DataTypeNames.STRING);

// 3. Create a detached row from the table schema and populate it before insertion
IDataRow departmentDataRow = DataRowExtensions.CreateRowFromColumns(departmentDataTable.Columns);
departmentDataRow.UpdateDataFieldValue("Id", 1);
departmentDataRow.UpdateDataFieldValue("Name", "Customer Service");

// 4. Insert the populated row into the table
dataSet.AddRow("Department", departmentDataRow);

Notes

 

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.