is it possable to display only 10 rows in a datagrid?
thanks:wave:
Printable View
is it possable to display only 10 rows in a datagrid?
thanks:wave:
Here's at least one way to do it with your SQL statement. (assuming MS SQL Server usage since no info was given)
sql Code:
select top 10 * from myTable
vb Code:
SELECT [Item Code], [Item Description], [Item Price], Type, [Type of software], [Product type], [Size], Make, [Times Viewed] SELECT [Times Viewed] 10 * FROM Items ORDER BY [Times Viewed] DESC
this is what i have and it doesnt work :S am i doin it right?
thanks
You need to give more details... Is it a DataGrid or a DataGridView? Is it data bound? Where does the data come from?... Do you have more than 10 rows of data and you want to display them in groups of 10 (something like a paged GridView)?
You don't have the TOP keyword anywhere in there and you don't need a separate SELECT clause for it. It goes before the columns you are SELECTing.
Read here and here.
EDIT: And, yes, more info would be helpful.Code:SELECT top 10
[Item Code], [Item Description], [Item Price], Type, [Type of software], [Product type], [Size], Make, [Times Viewed]
ORDER BY [Times Viewed] DESC
the data comes from a external access database
i have a times viewed on a product and i want it to show the top 10 most viewed.
it is in a data grid view and the data is bound to the data grid
and yes i have more than 10 rows
thanks.
So you simply query your database for the top 10 most viewed records and assign the result datatable to your datagridView.datasource.
Nmadd already showed you how to write the query.
SELECT TOP 10 [Times Viewed], [Item Description], [Item Code], [Item Price], Type, [Type of software], [Product type], [Size], Make
FROM Items
shows 10 results but not top ten most viewed
SELECT TOP 10 [Times Viewed], [Item Description], [Item Code], [Item Price], Type, [Type of software], [Product type], [Size], Make
FROM Items
ORDER BY [Times Viewed] DESC
shows 13 results but are ordered descending
The 2nd query should work... Did you clear your datatable before filling it using the 2nd query? If your datatable already has rows in it, the fill will just add more rows to the existing rows collection.
What database are you using? The second query would only return 10 records in SQL Server.
It may be that the one you're running it on groups the results together when you use a TOP and an ORDER BY, so that if there are two matches for the third highest and three matches for the sixth highest, then those extra three records would be included in the top 10. Try ordering it by ORDER BY [Times Viewed] DESC, [Item Code]. If that's the issue, adding another filter into the ORDER BY may solve it.