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. Remove a certain row from the Datatable [modified]

Remove a certain row from the Datatable [modified]

Scheduled Pinned Locked Moved C#
question
3 Posts 3 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.
  • N Offline
    N Offline
    NewToAspDotNet
    wrote on last edited by
    #1

    Hi All, I have a datatable : id name duration 01 001 00:10 02 002 00:20 03 003 00:10 As you can see, rows 0 and 2 have the same duration: 00:10 Now how can i make a algorimte to remove all those rows(except ONE of those rows) that has the same duration from my datatable ? Thanx.

    modified on Sunday, July 20, 2008 8:20 AM

    W G 2 Replies Last reply
    0
    • N NewToAspDotNet

      Hi All, I have a datatable : id name duration 01 001 00:10 02 002 00:20 03 003 00:10 As you can see, rows 0 and 2 have the same duration: 00:10 Now how can i make a algorimte to remove all those rows(except ONE of those rows) that has the same duration from my datatable ? Thanx.

      modified on Sunday, July 20, 2008 8:20 AM

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

      Hi, perhaps the easiest way is to sort your datatable by duration using Select method and then iterate the results and delete the duplicate durations. Hope this helps, Mika

      1 Reply Last reply
      0
      • N NewToAspDotNet

        Hi All, I have a datatable : id name duration 01 001 00:10 02 002 00:20 03 003 00:10 As you can see, rows 0 and 2 have the same duration: 00:10 Now how can i make a algorimte to remove all those rows(except ONE of those rows) that has the same duration from my datatable ? Thanx.

        modified on Sunday, July 20, 2008 8:20 AM

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        Group by duration and use min(id) to get one of the records to keep, and use having to get the ones where count(*) > 1. Now join this result in a delete on the table, and specify the ones where id is different and duration is the same.

        Despite everything, the person most likely to be fooling you next is yourself.

        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