|
-
Apr 22nd, 2008, 07:55 AM
#1
Thread Starter
Member
[2005] max of 10 rows in datagrid
is it possable to display only 10 rows in a datagrid?
thanks
-
Apr 22nd, 2008, 08:22 AM
#2
Re: [2005] max of 10 rows in datagrid
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
-
Apr 22nd, 2008, 08:31 AM
#3
Thread Starter
Member
Re: [2005] max of 10 rows in datagrid
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
-
Apr 22nd, 2008, 08:38 AM
#4
Re: [2005] max of 10 rows in datagrid
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)?
-
Apr 22nd, 2008, 08:40 AM
#5
Re: [2005] max of 10 rows in datagrid
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.
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
EDIT: And, yes, more info would be helpful.
-
Apr 22nd, 2008, 08:41 AM
#6
Thread Starter
Member
Re: [2005] max of 10 rows in datagrid
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.
-
Apr 22nd, 2008, 08:52 AM
#7
Re: [2005] max of 10 rows in datagrid
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.
-
Apr 22nd, 2008, 10:02 AM
#8
Thread Starter
Member
Re: [2005] max of 10 rows in datagrid
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
-
Apr 22nd, 2008, 12:20 PM
#9
Re: [2005] max of 10 rows in datagrid
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.
-
Apr 22nd, 2008, 12:27 PM
#10
Re: [2005] max of 10 rows in datagrid
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.
(VB/C#) is clearly superior to (C#/VB) because it (has/doesn't have) <insert trivial difference here>.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|