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. Data in DataTables

Data in DataTables

Scheduled Pinned Locked Moved C#
helpquestion
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.
  • E Offline
    E Offline
    exhaulted
    wrote on last edited by
    #1

    Hi all, I have a DataTable object and the 4th column has DateTime objects stored in it. To get at the DateTimes i am doing the following. DateTime dt; for (int x = 0; x < Table.Rows.Count; x++) { dt = (DateTime)Table.Rows[x].ItemArray[3] ..... Some other code here ..... } Is there any way of getting at the DateTime object in the column without casting? This is my biggest overhead by far in the method which is fine for a few hundred iterations but sometimes i am going through tens of thousands of iterations and it's a tad slow. Anyone able to help?? Cheers Kev

    R 1 Reply Last reply
    0
    • E exhaulted

      Hi all, I have a DataTable object and the 4th column has DateTime objects stored in it. To get at the DateTimes i am doing the following. DateTime dt; for (int x = 0; x < Table.Rows.Count; x++) { dt = (DateTime)Table.Rows[x].ItemArray[3] ..... Some other code here ..... } Is there any way of getting at the DateTime object in the column without casting? This is my biggest overhead by far in the method which is fine for a few hundred iterations but sometimes i am going through tens of thousands of iterations and it's a tad slow. Anyone able to help?? Cheers Kev

      R Offline
      R Offline
      Robert Rohde
      wrote on last edited by
      #2

      When using the DataTable you will have to do the casting. One solution would be to take another data structure. You should also try not taking the ItemArray property as I think it produces a bit overhead (Im not 100% in this):

      DateTime dt;

      for (int x = 0; x < Table.Rows.Count; x++)
      {
      dt = (DateTime)Table.Rows[x][3]
      .....
      Some other code here
      .....
      }

      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