Table of Contents

Class DataTransferRowCollection

Namespace
Cuemon.Data
Assembly
Cuemon.Data.dll

Represents a collection of DataTransferRow objects for a table in a database. This class cannot be inherited.

public sealed class DataTransferRowCollection : IEnumerable<DataTransferRow>, IEnumerable
Inheritance
DataTransferRowCollection
Implements

Examples

The following example demonstrates how to use to work with rows returned from a database query via an .

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

namespace MyApp.Data
{
    public sealed class DataTransferRowCollectionExample
    {
        public void Demonstrate()
        {
            var table = new DataTable("Products");
            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, "Apples", new DateTime(2024, 1, 2, 3, 4, 5, DateTimeKind.Utc), "Fresh");
            table.Rows.Add(2, "Bananas", new DateTime(2024, 2, 3, 4, 5, 6, DateTimeKind.Utc), DBNull.Value);

            using var reader = table.CreateDataReader();
            DataTransferRowCollection rows = DataTransfer.GetRows(reader);

            Console.WriteLine("Columns: " + string.Join(", ", rows.ColumnNames));
            Console.WriteLine($"Row count: {rows.Count}");

            DataTransferRow firstRow = rows[0];
            Console.WriteLine(firstRow.ToString());
            Console.WriteLine($"First row name: {firstRow["Name"]}");
            Console.WriteLine($"Created: {firstRow.As<DateTime>("Created"):O}");

            DataTransferRow secondRow = rows[1];
            Console.WriteLine($"Second row notes are null: {secondRow["Notes"] == null}");
            Console.WriteLine($"Contains first row: {rows.Contains(firstRow)}");
            Console.WriteLine($"Index of first row: {rows.IndexOf(firstRow)}");
        }
    }
}

Properties

ColumnNames

Gets the column names that is present in this DataTransferRow.

public IEnumerable<string> ColumnNames { get; }

Property Value

IEnumerable<string>

The column names of a table-row in a database.

Count

Gets the number of elements contained in the ICollection<T>.

public int Count { get; }

Property Value

int

The count.

this[int]

Gets the DataTransferRow at the specified index.

public DataTransferRow this[int index] { get; }

Parameters

index int

The zero-based index of the row to return.

Property Value

DataTransferRow

The specified DataTransferRow.

Methods

Contains(DataTransferRow)

Determines whether the ICollection<T> contains a specific value.

public bool Contains(DataTransferRow item)

Parameters

item DataTransferRow

The object to locate in the ICollection<T>.

Returns

bool

true if item is found in the ICollection<T>; otherwise, false.

GetEnumerator()

Returns an enumerator that iterates through the collection.

public IEnumerator<DataTransferRow> GetEnumerator()

Returns

IEnumerator<DataTransferRow>

A IEnumerator<T> that can be used to iterate through the collection.

IndexOf(DataTransferRow)

Determines the index of a specific item in the IList<T>.

public int IndexOf(DataTransferRow item)

Parameters

item DataTransferRow

The object to locate in the IList<T>.

Returns

int

The index of item if found in the list; otherwise, -1.