Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Select Top 10 in a dataTable???

Select Top 10 in a dataTable???

Scheduled Pinned Locked Moved C#
questiondatabasetutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    luckyShek
    wrote on last edited by
    #1

    Hi! I want to select only 10 rows from a dataTable each time, just as from a database("SELECT TOP 10 FROM orders WHERE ID <100 ORDER BY ID"). for example: DataTable myTable = new DataTable("orders"); DataRow[] rows = myTable.Select("TOP 10 ID < 100"); 1)How can I write the correct statement. 2)Can I ues "TOP" key word or there's other way to do it? Thank you very much.:rose:

    H 1 Reply Last reply
    0
    • L luckyShek

      Hi! I want to select only 10 rows from a dataTable each time, just as from a database("SELECT TOP 10 FROM orders WHERE ID <100 ORDER BY ID"). for example: DataTable myTable = new DataTable("orders"); DataRow[] rows = myTable.Select("TOP 10 ID < 100"); 1)How can I write the correct statement. 2)Can I ues "TOP" key word or there's other way to do it? Thank you very much.:rose:

      H Offline
      H Offline
      HahnTech
      wrote on last edited by
      #2

      I'm kinda new to this but this is how i did it. SqlCommand cmd = new SqlCommand(("SELECT TOP 10 FROM orders WHERE ID <100 ORDER BY ID",SQLConn); cmd.CommandType = CommandType.Text; SqlDataReader SQLData = cmd.ExecuteReader(); DataTable My_DataTable = SQLData.GetSchemaTable(); int iColumns = My_DataTable.Rows.Count; //shuld be 10 while(SQLData.Read()) { string sOut = ""; for(int i=0; i

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups