How to retrieve some records from the DataTable

Amatya
Posted by Amatya under C# category on | Points: 40 | Views : 217
Here we are assuming that DataTable dt are having 20 records and from that dt we want to retrieve only first 10 records.

The below code snippet will work in this case

private DataTable GethreeRows(DataTable dt)
{
DataTable newdt = dt.Clone();
for(int i=0;i<10;i++)
{
DataRow row = dt.Rows[i];
newdt .Rows.Add(row);
}
return newdt ;
}


Hope it will help you guys.
Thanks

Comments or Responses

Login to post response