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. Database & SysAdmin
  3. Database
  4. Using DataTable.Select in the slickest way possible

Using DataTable.Select in the slickest way possible

Scheduled Pinned Locked Moved Database
databaseperformance
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.
  • J Offline
    J Offline
    jesarg
    wrote on last edited by
    #1

    I recently have had the task of converting SQL statements that select directly from the database to DataTable.Select statements that select from a cache of records in memory. The SQL statements use a single table and are along the lines of:

    SELECT node.Name, parentNode.Name, rootNode.Name
    FROM (nodes node INNER JOIN nodes parentNode ON node.ParentID = parentNode.ID)
    INNER JOIN nodes rootNode ON node.RootID = rootNode.ID
    WHERE node.format = 5;

    Assuming I have a cache of the "nodes" table in memory (as a large DataTable), I can simulate this SQL statement with nested for / foreach loops, intermediate DataTables, and simple DataTable.Select statements. However, I was wondering if there's a slicker way of using the DataTable.Select that eliminates the need of doing so much looping and creating intermediate tables for the results.

    W 1 Reply Last reply
    0
    • J jesarg

      I recently have had the task of converting SQL statements that select directly from the database to DataTable.Select statements that select from a cache of records in memory. The SQL statements use a single table and are along the lines of:

      SELECT node.Name, parentNode.Name, rootNode.Name
      FROM (nodes node INNER JOIN nodes parentNode ON node.ParentID = parentNode.ID)
      INNER JOIN nodes rootNode ON node.RootID = rootNode.ID
      WHERE node.format = 5;

      Assuming I have a cache of the "nodes" table in memory (as a large DataTable), I can simulate this SQL statement with nested for / foreach loops, intermediate DataTables, and simple DataTable.Select statements. However, I was wondering if there's a slicker way of using the DataTable.Select that eliminates the need of doing so much looping and creating intermediate tables for the results.

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      The Select method in DataTable is quite restricted. You cannot for example join tables, create hierarchical queries etc. I didn't quite understand why you have to loop or create intermediate results since you didn't include your actual data table usage. I'm guessing that it's because of those restrictions I mentioned. If that's the case, I'd suggest that when building the cached datatable, use the database server ability to execute complex queries and in the datatable store the information in simpler form. Since this is mostly for reading the data from the cache, denormalization is one way to make the data more easy to use.

      The need to optimize rises from a bad design.My articles[^]

      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