views:

195

answers:

2

With the help of you guys, I have created an object that is similiar to the recordset in classic asp.

public class RecordSet: List<Dictionary<string, object>>
{

}

So I can access the data like:

RecordSet rs = new RecordSet();

rs[rowID]["columnName"];

How can I get access like this also, i.e. ordinal referece:

rs[rowId][2];

Please don't ask me why I just don't use a datatable, this is partly for fun and learning and testing hehe

A: 

Also you want to look at the IEnumerable interface, which you can implement to be able to 'foreach' loop through the class's rows.

Wim Haanstra
+3  A: 

Something that would work more like a RecordSet could look like this:

public class RecordSet {

   private Dictionary<string, int> _nameLookup;
   private List<List<object>> _rows;
   private int _currentRow;

   ...

   public object this[int index] {
      return _rows[_currentRow][index];
   }

   public object this[string name] {
      return this[_nameLookup[name]];
   }

   ...

}
Guffa