DataSet.TryGetTable Method
Attempts to get a table by name without throwing. This method is useful for dynamic workflows (plugins, optional modules, conditional UI) where a table may or may not exist.
Namespace: PocoDataSet.Data
Assembly: PocoDataSet.Data.dll
/// <summary>
/// Attempts to get a table by name.
/// IDataSet interface implementation
/// </summary>
/// <param name="tableName">Table name.</param>
/// <param name="dataTable">When this method returns true, contains the table.</param>
/// <returns>True if the table exists; otherwise false.</returns>
public bool TryGetTable(string tableName, out IDataTable? dataTable)
// 1. Create a data set with required Employee data table and optional Payroll data table
IDataSet dataSet = DataSetFactory.CreateDataSet();
dataSet.AddNewTable("Employee");
// 2. Try get Payroll data table, which is not part of data set
if (dataSet.TryGetTable("Payroll", out IDataTable? payrollDataTable))
{
// If Payroll data tble exists then process payroll data
int payrollColumnCount = payrollDataTable.Columns.Count;
}
// 3. Try get Employee data table, which is part of data set
if (dataSet.TryGetTable("Employee", out IDataTable? employeeDataTable))
{
// If Employee data tble exists then process employee data
}
else
{
throw new InvalidOperationException("Required table Employee is missing.");
}
Table of Content POCO DataSet API References POCO DataSet Types 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.