How to get N row from datatable in C#

  • Home
  • Blog
  • How to get N row from datatable in C#

Recently one of my friend was needed only first three rows of data table and so he asked me and I have multiple solutions for that. So thought it would be great idea to share with you guys. There are two ways to solve this problem.

  1. With normal for loop
  2. With lamda expression and linq

Following is code from where we can get 3 rows of data table.

private  DataTable GetFirst3RowViaFor(DataTable dataTable) {
    DataTable newDataTable = dataTable.Clone();
    for(int i=0;i