Table of Contents

Class DataTransferRow

Namespace
Cuemon.Data
Assembly
Cuemon.Data.dll

Represents the row of a table in a database. This class cannot be inherited.

public sealed class DataTransferRow
Inheritance
DataTransferRow

Examples

DataTransferRow provides access to data reader field values by index, column name, or DataTransferColumn object, including type-safe access via generic methods and automatic DBNull to null conversion. This example creates a DataTable with Id, Name, Created, and Notes columns containing two rows (one with a DBNull note), then retrieves a DataTransferRowCollection via DataTransfer.GetRows. It accesses values using all three lookup approaches — first[0] by index, first["Name"] by column name, and first[idCol] by column object — and uses As<int>("Id") for type-safe access. Console output confirms each value, shows null for the DBNull case, and displays the string representation of the row.

using System;
using System.Data;
using Cuemon.Data;

namespace MyApp.Data
{
    public static class DataTransferRowExamples
    {
        public static void Demonstrate()
        {
            // Build a DataTable to simulate a database result set.
            var table = new DataTable();
            table.Columns.Add("Id", typeof(int));
            table.Columns.Add("Name", typeof(string));
            table.Columns.Add("Created", typeof(DateTime));
            table.Columns.Add("Notes", typeof(string));
            table.Rows.Add(1, "Alice", new DateTime(2024, 1, 2, 3, 4, 5, DateTimeKind.Utc), "First");
            table.Rows.Add(2, "Bob", new DateTime(2024, 2, 3, 4, 5, 6, DateTimeKind.Utc), DBNull.Value);

            // Convert the reader to rows.
            using (IDataReader reader = table.CreateDataReader())
            {
                DataTransferRowCollection rows = DataTransfer.GetRows(reader);

                // Access individual rows.
                DataTransferRow first = rows[0];
                DataTransferRow second = rows[1];

                Console.WriteLine("Row numbers: {0}, {1}", first.Number, second.Number);

                // Access values by column index.
                object idValue = first[0];
                Console.WriteLine("First row Id: {0}", idValue);

                // Access values by column name.
                object nameValue = first["Name"];
                Console.WriteLine("First row Name: {0}", nameValue);

                // Access values by DataTransferColumn object.
                DataTransferColumn idCol = first.Columns["Id"];
                object viaColumn = first[idCol];
                Console.WriteLine("First row Id (via column): {0}", viaColumn);

                // Type-safe access using generics.
                int idTyped = first.As<int>("Id");
                DateTime created = first.As<DateTime>("Created");
                Console.WriteLine("Typed: Id={0}, Created={1:O}", idTyped, created);

                // Nullable value (DBNull is converted to null).
                object notes = second["Notes"];
                Console.WriteLine("Second row Notes is null: {0}", notes == null);

                // String representation of the row.
                Console.WriteLine("Row string: {0}", first);

}}}
}

Properties

Columns

Gets the associated columns of this row.

public DataTransferColumnCollection Columns { get; }

Property Value

DataTransferColumnCollection

The associated columns of this row.

this[DataTransferColumn]

Gets the value of a DataTransferColumn from the Columns with the specified column.

public object this[DataTransferColumn column] { get; }

Parameters

column DataTransferColumn

The column from which to return the value from.

Property Value

object

An Object that contains the data of the column.

this[int]

Gets the value of a DataTransferColumn from the Columns with the specified index.

public object this[int index] { get; }

Parameters

index int

The zero-based index of the column from which to return the value from.

Property Value

object

An Object that contains the data of the column.

this[string]

Gets the value of a DataTransferColumn from the Columns with the specified name.

public object this[string name] { get; }

Parameters

name string

The name of the column from which to return the value from.

Property Value

object

An Object that contains the data of the column.

Number

Gets the row number.

public int Number { get; }

Property Value

int

The row number.

Methods

As<TResult>(DataTransferColumn)

Gets the value of a DataTransferColumn from the Columns with the specified column.

public TResult As<TResult>(DataTransferColumn column)

Parameters

column DataTransferColumn

The column from which to return the value from.

Returns

TResult

The value associated with the column converted to the specified TResult.

Type Parameters

TResult

The type of the result.

As<TResult>(int)

Gets the value of a DataTransferColumn from the Columns with the specified index.

public TResult As<TResult>(int index)

Parameters

index int

The zero-based index of the column from which to return the value from.

Returns

TResult

The value associated with the zero-based index of a column converted to the specified TResult.

Type Parameters

TResult

The type of the result.

As<TResult>(string)

Gets the value of a DataTransferColumn from the Columns with the specified name.

public TResult As<TResult>(string name)

Parameters

name string

The name of the column from which to return the value from.

Returns

TResult

The value associated with the name of a column converted to the specified TResult.

Type Parameters

TResult

The type of the result.

ToString()

Returns a string that represents this instance.

public override string ToString()

Returns

string

A string that represents this instance.