Results 1 to 10 of 10

Thread: [2005] max of 10 rows in datagrid

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2006
    Posts
    62

    [2005] max of 10 rows in datagrid

    is it possable to display only 10 rows in a datagrid?
    thanks

  2. #2
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    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:
    1. select top 10 * from myTable

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2006
    Posts
    62

    Re: [2005] max of 10 rows in datagrid

    vb Code:
    1. SELECT     [Item Code], [Item Description], [Item Price], Type, [Type of software], [Product type], [Size], Make, [Times Viewed]
    2. SELECT [Times Viewed] 10 * FROM Items
    3. ORDER BY [Times Viewed] DESC

    this is what i have and it doesnt work :S am i doin it right?
    thanks

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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)?

  5. #5
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    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.

  6. #6

    Thread Starter
    Member
    Join Date
    Nov 2006
    Posts
    62

    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.

  7. #7
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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.

  8. #8

    Thread Starter
    Member
    Join Date
    Nov 2006
    Posts
    62

    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

  9. #9
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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.

  10. #10
    Frenzied Member
    Join Date
    May 2006
    Location
    Toronto, ON
    Posts
    1,093

    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
  •  



Click Here to Expand Forum to Full Width