Values Property

Overview

The Values property returns a read-only view of the row current field values. Think of Values as a read-only window into the row. You can look through the window and see changes happen, but you cannot reach through the window to change anything. To change a value, you must modify the actual data row. If the data row is modified, the Values property will reflect the updated data.

The Values property returns dictionary, which uses the column name as the key and the current field value as the value. Values is intended for scenarios where you want to treat a row like a name/value bag: logging, auditing, UI rendering, serialization, or building parameter sets. Use the IDataRow indexer (row["ColumnName"]) to change values.

Namespace and Assembly

Namespace: PocoDataSet.Data
Assembly: PocoDataSet.Data.dll

Usage Example

Enumerate all values and write an audit log entry:

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

// 2. Create an empty data table
IDataTable employeeDataTable = dataSet.AddNewTable("Employee");
employeeDataTable.AddColumn("Id", DataTypeNames.INT32);
employeeDataTable.AddColumn("FirstName", DataTypeNames.STRING);
employeeDataTable.AddColumn("LastName", DataTypeNames.STRING);
employeeDataTable.AddColumn("IsActive", DataTypeNames.BOOLEAN);

// 3. Create a new row
IDataRow employeeDataRow = employeeDataTable.AddNewRow();
employeeDataRow["Id"] = 1001;
employeeDataRow["FirstName"] = "John";
employeeDataRow["LastName"] = "Smith";
employeeDataRow["IsActive"] = true;

// 4. Iterate over Values to build an audit string
StringBuilder sb = new StringBuilder();
foreach (KeyValuePair<string, object?> pair in employeeDataRow.Values)
{
  string valueText = pair.Value == null ? "<null>" : pair.Value.ToString();
  sb.Append(pair.Key);
  sb.Append("=");
  sb.Append(valueText);
  sb.Append("; ");
}

string auditLine = sb.ToString();

Copy the current values into a standalone dictionary (snapshot) for later comparison:

// 1. Create a snapshot dictionary
Dictionary<string, object?> snapshot = new Dictionary<string, object?>(StringComparer.Ordinal);
foreach (KeyValuePair<string, object?> pair in employeeDataRow.Values)
{
  snapshot[pair.Key] = pair.Value;
}

// 2. Modify the row later (Values changes, snapshot does not)
employeeDataRow["LastName"] = "Johnson";

// 3. Compare snapshot vs. current values
object? oldLastName = snapshot["LastName"];
object? newLastName = employeeDataRow["LastName"];

 

Table of Content POCO DataSet API References POCO DataSet Types 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.