I need to bring top 100 records from an existing populated dataset. I am attaching the snippet of my code

any change in stored procedure is not an option. The dataset which has data is dsReportData
Exisiting snippet of code.


    Public Sub BindGrid(ByVal pisRebind As Boolean, ByVal poFetchingOptions As MZKObj.FetchingOptions)
        If pisRebind Then
            Dim dsReportData As DataSet
            Dim l_oINT_SimpleExtracts As INT_SimpleExtracts

            If _mintExtracts_ID > 0 Then
                l_oINT_SimpleExtracts = New INT_SimpleExtracts(_mintExtracts_ID, TEMSSecurity.UserDistrict)
                l_oINT_SimpleExtracts.CreateObj()
                If Not IsDBNull(l_oINT_SimpleExtracts.ExtractType) AndAlso (l_oINT_SimpleExtracts.ExtractType = "Stored Procedure" Or l_oINT_SimpleExtracts.ExtractType = "Customer Stored Procedure") Then
                    dsReportData = l_oINT_SimpleExtracts.GetExtractViewGridDS(_mintExtracts_ID, "", l_oINT_SimpleExtracts.StoredProcedureName, l_oINT_SimpleExtracts.Parameters, TEMSSecurity.UserDistrict)
                Else
                    Dim l_strQuesy As String = GetAdhocQuery(TEMSSecurity.UserDistrict, l_oINT_SimpleExtracts.Query_ID, l_oINT_SimpleExtracts)
                    dsReportData = l_oINT_SimpleExtracts.GetExtractViewGridDS(_mintExtracts_ID, l_strQuesy, "", "", TEMSSecurity.UserDistrict)
                End If
            End If

            Dim l_oDataColumn As DataColumn
            Dim l_oDataGridColumn As MZKGrids.MazikGrid.MZKExtBoundColumn
            For Each l_oDataColumn In dsReportData.Tables(0).Columns
                l_oDataGridColumn = New MZKGrids.MazikGrid.MZKExtBoundColumn
                l_oDataGridColumn.HeaderText = l_oDataColumn.ColumnName
                l_oDataGridColumn.DataField = l_oDataColumn.ColumnName
                dgrReportData.Columns.Add(l_oDataGridColumn)
            Next

            dgrReportData.DataSource = dsReportData.Tables(0).DefaultView


--Need to pull 100 rows here



           dgrReportData.DataBind()

            If dsReportData.Tables(0).DefaultView.Count > 100 Then
                cntScriptManager.EnablePartialRendering = True
            End If
        End If
    End Sub
codedeveloper1Asked:
Who is Participating?
 
APoPhySptCommented:
Hy...

Try using 'Linq'. Using link you can somewhat make a query to a variable sort of like you would in sql.. this way getting the top 100 items of a variable would be easy:

 
Public Sub Linq21()
    Dim customers = GetCustomerList()

    Dim first3WAOrders = From c In customers, o In c.Orders _
        Where c.Region = "WA" Take 3 _
        Select c.CustomerID, o.OrderID, o.OrderDate

    Console.WriteLine("First 3 orders in WA:")
    For Each ord In first3WAOrders
        ObjectDumper.Write(ord)
    Next
End Sub

Open in new window


where 'take' is the number of record you want to fetch from the variable.

There are other examples at: http://msdn.microsoft.com/en-us/vstudio/bb688088
0
 
codedeveloper1Author Commented:
Thanks for the help. I used the the function that accepts a datatable and count and returns a newly populated data table with rows equal to count.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.