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. DataTable searchs

DataTable searchs

Scheduled Pinned Locked Moved C#
tutorialquestion
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.
  • M Offline
    M Offline
    Moon Boy
    wrote on last edited by
    #1

    Hi, how i search for repeated items in a DataTable? Example: I have the Column Name and Email. I want to delete every Name and Email repeateds. Thanks.

    T H 2 Replies Last reply
    0
    • M Moon Boy

      Hi, how i search for repeated items in a DataTable? Example: I have the Column Name and Email. I want to delete every Name and Email repeateds. Thanks.

      T Offline
      T Offline
      TigerNinja_
      wrote on last edited by
      #2

      For better programming practices use a UniqueConstraint on your DataTable. To learn more about constraints and data integrity see this msdn article http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconaddingconstraintstodataset.asp[^] HTH

      R.Bischoff

      Denn Gott hat die Menschen so sehr geliebt, daß er seinen einzigen Sohn für sie hergab. Jeder, der an ihn glaubt, wird nicht verlorengehen, sondern das ewige Leben haben

      1 Reply Last reply
      0
      • M Moon Boy

        Hi, how i search for repeated items in a DataTable? Example: I have the Column Name and Email. I want to delete every Name and Email repeateds. Thanks.

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        See the DataTable.Select command. It uses the same expressions as DataColumn.Expression. You could use this to get a DataRow[] array and then remove each of those array members from the DataTable. Another way would be to sort the DataTable and iterate - not enumerate, which is what foreach does - through it keeping track of the last DataRow and comparing it with the current DataRow. If they contain the same data, remove the current DataRow (which is why you don't enumerate - changing a collection that you're enumerating throws an exception). Don't forget to decrement your index for the for loop since it will be incremented with the next iteration (you want to keep the index the same since you just removed a DataRow).

        Microsoft MVP, Visual C# 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