Item[string] Indexer

Overview

The Item[string] indexer allows you to get or set the current value of a data row column by its name. This indexer provides convenient access to row values using array-like syntax.

Reading a value using the indexer returns null if the specified column does not exist or if the stored value is null.

Writing a value using the indexer updates the row value and may change the row’s DataRowState. If the row is in the Unchanged state, assigning a different value causes the framework to capture original values and mark the row as Modified.

Namespace and Assembly

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

Usage Example

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

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

// 3. Create a new row by AddNewRow method on data table, the row state is Added
IDataRow departmentDataRow = departmentDataTable.AddNewRow();

// 4. Assign value using the indexer
departmentDataRow["Name"] = "Emergency";

// 5. Read value using the indexer
object? departmentName = departmentDataRow["Name"];

// 6. Call AcceptChanges method to set row state into Unchanged
departmentDataRow.AcceptChanges();

// 7. Modify value using the indexer to put row into Modified state
departmentDataRow["Name"] = "Reception";

 

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.