GetDataFieldValue Method

Overview

The GetDataFieldValue method reads a value from an IDataRow field and returns it as a strongly typed value. If the raw value is not already of the requested type, the method attempts to convert it using the framework’s composite value converter.

This method is intentionally tolerant: if conversion is not possible, it returns default(T) instead of throwing. The only exception case is when the requested field (column) does not exist in the row.

Declaration

/// <summary>
/// Gets data field value
/// </summary>
/// <typeparam name="T">Data field value type</typeparam>
/// <param name="dataRow">Data row</param>
/// <param name="columnName">Column name</param>
/// <returns>Data field value</returns>
/// Exception is thrown if table does not contain the column with specified name
public static T? GetDataFieldValue<T>(this IDataRow? dataRow, string columnName)

Namespace and Assembly

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

Behavior

Usage Example

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

// 2. Create an empty Department table
IDataTable departmentDataTable = dataSet.AddNewTable("Department");
departmentDataTable.AddColumn("Id", DataTypeNames.INT32);
departmentDataTable.AddColumn("Name", DataTypeNames.STRING);

// 3. Add a new row to the Department table
IDataRow departmentDataRow = departmentDataTable.AddNewRow();
departmentDataRow["Id"] = 1;
departmentDataRow["Name"] = "Customer Service";

// 4. Read back a value from the row, observe "Customer Service" as a name
string? name = departmentDataRow.GetDataFieldValue("Name");

 

Table of Content POCO DataSet DataRow 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.