GetFieldValue Method

Overview

The GetFieldValue method retrieves a strongly typed value from a specific table, row, and column (case insensitive) within an IDataSet. It is a convenience wrapper that performs table lookup, bounds checking, and column validation before delegating value extraction to DataRowExtensions.GetDataFieldValue.

This method is useful when you need to read a single value without directly navigating tables and rows or casting from object.

Declaration

/// <summary>
/// Gets field value
/// </summary>
/// <typeparam name="T">Value type</typeparam>
/// <param name="dataSet">Data set</param>
/// <param name="tableName">Table name</param>
/// <param name="rowIndex">Row index</param>
/// <param name="columnName">Column name</param>
/// <returns>Field value</returns>
/// <exception cref="KeyNotFoundException">Exception is thrown if dataset does not contain a table with specified name or column with specified name in that table</exception>
/// <exception cref="ArgumentOutOfRangeException">Exception is thrown if table does not have row with specified index</exception>
public static T? GetFieldValue<T>(this IDataSet? dataSet, string tableName, int rowIndex, string columnName)

Namespace and Assembly

Namespace: PocoDataSet.Extensions
Assembly: PocoDataSet.Extensions.dll

Usage Example

// 1. Create an empty data set
IDataSet dataSet = DataSetFactory.CreateDataSet();

// 2. Create a table and add a row
IDataTable employeeTable = dataSet.AddNewTable("Employee");
employeeTable.AddColumn("Id", DataTypeNames.INT32);
employeeTable.AddColumn("FirstName", DataTypeNames.STRING);
employeeTable.AddColumn("LastName", DataTypeNames.STRING);

IDataRow employeeRow = employeeTable.AddNewRow();
employeeRow["Id"] = 1;
employeeRow["FirstName"] = "John";
employeeRow["LastName"] = "Doe";

// 3. Read a value using GetFieldValue
string? firstName = dataSet.GetFieldValue<string>("Employee", 0, "FirstName");

Notes

 

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.