Please disable your adblock and script blockers to view this page

How to get specified number of records from datatable in

Introduction: In previous articles i explained How to send emails in | How to set Smtp setting in web.config file to send email in and Difference between Delete and Truncate in sql server
and What is Page.IsValid and Page.Validate in ? and 20 differences between Stored procedures and Functions in Sql Server 

 Suppose you have 50 rows in DataTable named dt and you want to show only first 10 rows in the GridView then call the function SelectTopRows passing first parameter as your datatable object dt and second parameter as 10.This function will return first 10 rows from the datatable.Now you can bind that filtered datatable i.e. dtnew to your gridview.

C#.Net Code  to get specified number of records from datatable in

Public Function SelectTopRows(dt As DataTable, count As Integer) As DataTable
Dim dtnew As DataTable = dt.Clone()
For i As Integer = 0 To count - 1
dtnew .ImportRow(dt.Rows(i))
Return dtnew

End Function

VB.Net Code to get specified number of records from datatable in

public DataTable SelectTopRows(DataTable dt, int count)
DataTable dtnew  = dt.Clone();
for (int i = 0; i < count; i++)
return dtnew ;

Next Post »

If you have any question about any post, Feel free to ask.You can simply drop a comment below post or contact via Contact Us form. Your feedback and suggestions will be highly appreciated. Also try to leave comments from your account not from the anonymous account so that i can respond to you easily.. ConversionConversion EmoticonEmoticon