ContainsColumn Method
The ContainsColumn method determines whether a table contains a column
with the specified name. The comparison is performed in a case-insensitive manner.
This helper is typically used to validate schema assumptions before reading or writing values, especially when working with dynamically generated tables.
/// <summary>
/// Gets flag indicating whether data table contains column with specified name
/// </summary>
/// <param name="dataTable">Data table</param>
/// <param name="columnName">Column name</param>
/// <returns>Flag indicating whether data table contains column with specified name</returns>
public static bool ContainsColumn(this IDataTable? dataTable, string? columnName)
Namespace: PocoDataSet.Extensions
Assembly: PocoDataSet.Extensions.dll
dataTable is null, returns false.columnName is null or empty, returns false.dataTable.Columns and compares column names using
StringComparison.OrdinalIgnoreCase.
// 1. Create an empty data set and table
IDataSet dataSet = DataSetFactory.CreateDataSet();
IDataTable departmentTable = dataSet.AddNewTable("Department");
departmentTable.AddColumn("Id", DataTypeNames.INT32);
departmentTable.AddColumn("Name", DataTypeNames.STRING);
// 2. Check for columns
bool hasId = departmentTable.ContainsColumn("Id");
bool hasCode = departmentTable.ContainsColumn("Code");
Table of Content POCO DataSet DataTable Extensions Group DataTable 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.