DataTable.TryGetColumn Method
Attempts to get column metadata by name without throwing. This method is useful for dynamic rendering scenarios (metadata-driven UI, schema drift handling) where a column may be optional.
Namespace: PocoDataSet.Data
Assembly: PocoDataSet.Data.dll
/// <summary>
/// Attempts to get column metadata by name.
/// IDataTable interface implementation
/// </summary>
/// <param name="columnName">Column name.</param>
/// <param name="columnMetadata">When this method returns true, contains the column metadata.</param>
/// <returns>True if the column exists; otherwise false.</returns>
public bool TryGetColumn(string columnName, out IColumnMetadata? columnMetadata)
// 1. Create a data set
IDataSet dataSet = DataSetFactory.CreateDataSet();
// 2. Add Employee data table to data set
IDataTable employeeDataTable = dataSet.AddNewTable("Employee");
employeeTable.AddColumn("Id", DataTypeNames.INT32);
employeeTable.AddColumn("FirstName", DataTypeNames.STRING);
employeeTable.AddColumn("LastName", DataTypeNames.STRING);
// 3. Try get DepartmentId column, which is an optional column that may not be present in all versions of the data set
if (employeeDataTable.TryGetColumn("DepartmentId", out IColumnMetadata? departmentIdColumn))
{
// Use DepartmentId column metadata
string dataType = departmentIdColumn.DataType;
}
Table of Content POCO DataSet API References POCO DataSet Types 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.