GetFieldValue Method
The GetFieldValue method reads a field value from a table row and returns it as a strongly typed value.
It is a table-level convenience wrapper that validates the row index and column name (case insensitive) before delegating the actual
value extraction to DataRowExtensions.GetDataFieldValue<T>.
/// <summary>
/// Gets field value
/// </summary>
/// <typeparam name="T">Value type</typeparam>
/// <param name="dataTable">Data table</param>
/// <param name="rowIndex">Row index</param>
/// <param name="columnName">Column name</param>
/// <returns>Field value</returns>
/// <exception cref="KeyNotFoundException">Exception is thrown if table does not contain the column with specified name</exception>
/// <exception cref="ArgumentOutOfRangeException">Exception is thrown if table does not have row with specified index</exception>
public static T? GetFieldValue<T>(this IDataTable? dataTable, int rowIndex, string columnName)
Namespace: PocoDataSet.Extensions
Assembly: PocoDataSet.Extensions.dll
dataTable is null, returns default(T).rowIndex is within [0..Rows.Count-1]; otherwise throws.columnName (using ContainsColumn); otherwise throws.DataRowExtensions.GetDataFieldValue<T>(dataRow, columnName).
// 1. Create data set
IDataSet dataSet = DataSetFactory.CreateDataSet();
// 2. Add Employee data table to data set
IDataTable employeeDataTable = dataSet.AddNewTable("Employee");
employeeDataTable.AddColumn("Id", DataTypeNames.INT32);
employeeDataTable.AddColumn("FirstName", DataTypeNames.STRING);
employeeDataTable.AddColumn("LastName", DataTypeNames.STRING);
// 3. Add several rows to Employee data table
IDataRow employeeDataRow1 = employeeDataTable.AddNewRow();
employeeDataRow1["Id"] = 1;
employeeDataRow1["FirstName"] = "John";
employeeDataRow1["LastName"] = "Doe";
IDataRow employeeDataRow2 = employeeDataTable.AddNewRow();
employeeDataRow2["Id"] = 2;
employeeDataRow2["FirstName"] = "Sara";
employeeDataRow2["LastName"] = "Gor";
// 4. Call GetFieldValue method to get a value from the FirstName field of the first row, expected "John"
string? firstName = employeeDataTable.GetFieldValue
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.