var qrylinq = (from lstRow1 in dta2.AsEnumerable()
group lstRow1 by lstRow1.Field("Ids")
into lRow1
select new
{
Key = lRow1.Key,
LessFirst = lRow1.OrderBy(d => d.Field("newFCOffs")).Skip(1),
LessLast = lRow1.OrderBy(d => d.Field("newFCOns")).Take( lRow1.Count() -1)
}).ToList();
// How to go about your calculations
for (int i = 0; i < qrylinq.Count(); i++)
{
DataRow[] drFCOffs = qrylinq[i].LessFirst.ToArray();
DataRow[] drFCOns = qrylinq[i].LessLast.ToArray();
for( int j = 0; j < drFCOffs.Length; j++)
{
Console.WriteLine("Difference {0}", drFCOffs[j].Field("newFCOffs") - drFCOns[j].Field("newFCOns"));
}
}
// Just to display the query results
foreach (var gup in qrylinq)
{
Console.WriteLine("Group By ID {0}", gup.Key);
Console.WriteLine("\tnewFCOffs");
foreach (var dr in gup.LessFirst)
{
Console.WriteLine("\tDate and time = {0}", dr.Field("newFCOffs").ToString("yyy-MM-dd HH:mm:ss.fff"));
}
Console.WriteLine("\tnewFCOns");
foreach (var dr in gup.LessLast)
{
Console.WriteLine("\tDate and time = {0}", dr.Field("newFCOns").ToString("yyy-MM-dd HH:mm:ss.fff"));
}
Console.WriteLine("=====");
}
|