tags:

views:

24

answers:

1

Hi, I want to Enumerate Linq Query. Below i specified example.

EX:

 DataTable _slidingDataTable = new DataTable("test");

 for(int i=0; i<5;i++)
 {
  DataRow row = _slidingDataTable.NewRow();

   startPosition = DateTime.Now;
   for(int i=0; i<5;i++)
   {
      _slidingDataTable.Columns.Add("TransferTime");
       row[columnName] = startPosition ;
       _slidingDataTable.Columns.Add("TransferData");
       row[columnName] = "Test"+i;
    }

 _slidingDataTable.Rows.Add(row);
 }


 var query1 = from myRow in _slidingDataTable.AsEnumerable()
                        where myRow.Field<DateTime>("TransferTime") == startPosition
                        select myRow;

This query output should be collection of rows. How to get collection row & iterate.

A: 

In your context, query1 is an EnumerableRowCollection<DataRow> because you used _slidingDataTable.AsEnumerable(), and you can iterate over it like so :

foreach (DataRow row in query1)
{ 
    // Do stuff with that row
}
Dynami Le Savard