The C# SqlResultSet Class

SqlResultSet represents the rows returned by ExecuteQuery() on an ISqlConnection. It exposes result metadata such as column names and types and can be iterated using foreach to obtain SqlTuple objects.

For an overview see page SQL Classes

Class Definition

    public class SqlResultSet : IEnumerable<SqlTuple>, IEnumerable, IDisposable
    {
        // Properties
        public string[] ColumnNames { get; }
        public Type[] ColumnTypes { get; }
        public int NumberOfColumns { get; }

        // Methods
        public int GetColumnNo(string column);
        public void Close();
        public void Dispose();
        public IEnumerator<SqlTuple> GetEnumerator();
        IEnumerator IEnumerable.GetEnumerator();

    }

Member Descriptions

SqlResultSet class
Represents the result of an SQL query execution. Implements enumerable interfaces for iterating through result tuples (SqlTuple) and IDisposable for resource management.
ColumnNames
Gets the names of the result columns. The names are cached after the first access.
ColumnTypes
Gets an array of .NET Type objects describing the values returned in each column. The wrapper maps SQL engine types to C# runtime types such as long, double, string, DateTime, decimal, byte[], Sequence, and array types used for remote SQL sequence results.
NumberOfColumns
Returns the number of columns in the result set.
GetColumnNo(string)
Finds the zero-based index of a column by its name. The name comparison uses the column names returned by the result set metadata. Throws ArgumentException if the column is not found.
Close()
Closes the result set and releases its resources. This method is an alias for Dispose().
Dispose()
Releases all resources held by the result set: disposes the SqlCursor objects created from this result set, detaches the result from its parent connection, and closes the native result handle.
GetEnumerator() (generic)
Returns an enumerator for iterating through SqlTuple objects. Each call creates a new SqlCursor and registers it with the result set for coordinated cleanup.
GetEnumerator() (non-generic)
Explicit interface implementation of IEnumerable.GetEnumerator(). It creates and returns a SqlCursor in the same way as the generic enumerator method.
Iteration Pattern
Use foreach (SqlTuple row in resultSet) to iterate through the returned rows. Each enumeration creates a separate cursor over the same query result, so repeated enumeration starts with a new cursor.
Resource Management
Prefer a using statement or an explicit call to Close()/Dispose() so that result-set resources are released promptly. A finalizer exists as a safety net, but application code should not rely on it for normal cleanup.
Thread Safety
SqlResultSet instances are not thread-safe. Access from multiple threads requires external synchronization. Each thread should use its own connection and result set.
Column Access
Use GetColumnNo() to resolve column names to indices, then access values via SqlTuple indexer: row[columnIndex]. Type casting is required based on ColumnTypes.
Sequence-Valued Columns
If a query returns SQL sequence columns, the corresponding tuple values can be exposed as Sequence or sequence-array values depending on the query form and transport. Sequence objects obtained from a tuple should be disposed after use.