TryGetTable Method
The TryGetTable method attempts to retrieve a table from an IDataSet by name
without throwing exceptions. It follows the familiar "TryGet" pattern and returns a boolean
indicating success.
In addition to a direct key lookup, the method performs a fallback case-insensitive scan of the table names, which makes it resilient to casing differences between producers and consumers.
/// <summary>
/// Tries to get table from dataset by its name
/// </summary>
/// <param name="dataSet">Data set</param>
/// <param name="tableName">Table name</param>
/// <param name="table">Specified table</param>
/// <returns>True if table found, otherwise false</returns>
public static bool TryGetTable(this IDataSet? dataSet, string? tableName, out IDataTable? table)
Namespace: PocoDataSet.Extensions
Assembly: PocoDataSet.Extensions.dll
dataSet is null, returns false.
tableName is null or whitespace, returns false.
out parameter and returns true.
// 1. Create an empty data set
IDataSet dataSet = DataSetFactory.CreateDataSet();
// 2. Create a table
IDataTable departmentTable = dataSet.AddNewTable("Department");
// 3. Try to retrieve the table safely
if (dataSet.TryGetTable("department", out IDataTable? foundTable))
{
// foundTable is not null
}
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.