I generate a DataTable ( from non-SQL data ) and then use a DataView to filter records.
I want to limit the number of records in the final set of records , but I can not do this when I create a DataTable .
I resorted to deleting rows from the final result set:
DataView dataView = new DataView(dataTable); dataView.RowFilter = String.Format("EventDate > '{0}'", DateTime.Now); dataView.Sort = "EventDate"; dataTable = dataView.ToTable(); while (dataTable.Rows.Count > _rowLimit) dataTable.Rows[dataTable.Rows.Count - 1].Delete(); return dataTable;
Is there a more efficient way to limit the results?
Ian g source share