MCofer
asked on
How to get TOP 10 rows of a DataView
I want to filter a dataview to match the results of SELECT TOP 10
I am calling this from asp codebehind and do not want to make another trip to the database
The Row to filter is named "PartNum"
myDataView.RowFilter = "TOP 10 PartNum"
I am calling this from asp codebehind and do not want to make another trip to the database
The Row to filter is named "PartNum"
myDataView.RowFilter = "TOP 10 PartNum"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That was easy enough (its DataRowView not DataViewRow)
Thanks
Thanks
That's what happens when you write code in the comment block. No syntax checking!!!!
Bob
Bob
'For what it is worth, another simple solution:
Dim ds As DataSet = SomePropertyOrMethodToGetM yData
'create increment column for ordering
If Not ds.Tables(0).Columns.Conta ins("TopOr der") Then
Dim cOrder As New DataColumn("TopOrder", GetType(Integer))
cOrder.AutoIncrement = True
ds.Tables(0).Columns.Add(c Order)
End If
'filter data
Dim dv As New DataView(ds.Tables(0))
dv.RowFilter = "TopOrder <=" & MaxRecords.ToString
'Access your dataview for the filtered records
Dim ds As DataSet = SomePropertyOrMethodToGetM
'create increment column for ordering
If Not ds.Tables(0).Columns.Conta
Dim cOrder As New DataColumn("TopOrder", GetType(Integer))
cOrder.AutoIncrement = True
ds.Tables(0).Columns.Add(c
End If
'filter data
Dim dv As New DataView(ds.Tables(0))
dv.RowFilter = "TopOrder <=" & MaxRecords.ToString
'Access your dataview for the filtered records
You can't specify DataView RowFilter such as "TOP 10 PartNum".
It because RowFilter accept the name of a column followed by an operator and a value to filter on.
For example "LastName = 'Smith'"
But you can retrive top records from DataSet.Table and then bind they to datagrid.
Look at following function returning top rows:
Function GetTopRecords(ByVal dt, ByVal RowCount, ByVal _Start)
Dim _table As DataTable
_table = dt.Clone()
Dim i As Int32
For i = _Start To _Start + RowCount
If i >= dt.Rows.Count Then
Exit For
Else
_table.ImportRow(dt.Rows(i
End If
Next
Return _table
End Function