1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need some quick help with C#

Discussion in 'C, C++, C#' started by SHOwnsYou, Nov 20, 2009.

  1. SHOwnsYou

    SHOwnsYou Registered Member

    Joined:
    Jun 21, 2009
    Messages:
    94
    Likes Received:
    94
    [FONT=&quot]
    Ok, I am trying to retrieve a random record set from my OLEDB connected database.

    Code:
    OleDbDataAdapter adapter2 = new OleDbDataAdapter("Select top 5 url from stories ORDER BY rnd()", aConn);
    
    I tried this, but it returns the entire record set.

    Just using the sql
    Code:
     SELECT top 5 url FROM stories [code]
    
    Only returns 5 stories, but there seems to be no way to change which 5 are returned.
    [/FONT]
     
  2. SEO20

    SEO20 Elite Member

    Joined:
    Mar 25, 2009
    Messages:
    2,017
    Likes Received:
    2,259
    Selecting random in TSQL is not the best place to have such logic. But if you really must do that here is an article that will teach you more:

    http://www.kodyaz.com/articles/top-n-random-rows-foreach-category-or-group.aspx
     
    • Thanks Thanks x 1
  3. SHOwnsYou

    SHOwnsYou Registered Member

    Joined:
    Jun 21, 2009
    Messages:
    94
    Likes Received:
    94
    Thanks for the quick reply!

    I figured using oledb wasnt the best way to approach this, but I am more itnerested in giving this another test run.

    I do plan to rewrite it and make it more efficient, but right now I don't have the time.