Friday, March 28, 2014

SQL query related...


var table = new DataTable();
table.Columns.Add("Column1", typeof(int));
table.Columns.Add("Column2", typeof(DateTime));
table.Rows.Add(6565, DateTime.UtcNow.AddDays(6565));
table.Rows.Add(1212, DateTime.UtcNow.AddDays(1212));
table.Rows.Add(8514, DateTime.UtcNow.AddDays(8514));

var maxColumn1 = table.AsEnumerable().Max(x => x.Field<int>("Column1"));
var results = table.AsEnumerable().Where(x => x.Field<int>("Column1") == maxColumn1);



The last two lines can be consolidated, but will leave that exercise to you.

No comments:

Post a Comment