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. Comparing for Columns

Comparing for Columns

Scheduled Pinned Locked Moved C#
databasequestion
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.
  • Y Offline
    Y Offline
    Yonathan1111
    wrote on last edited by
    #1

    Hi everybody, I have DataSet which is filled by a database table called "schedule". And I want to compare the values of specific columns that are found in different rows, is possible? If it is, how? Thank you.

    P D 2 Replies Last reply
    0
    • Y Yonathan1111

      Hi everybody, I have DataSet which is filled by a database table called "schedule". And I want to compare the values of specific columns that are found in different rows, is possible? If it is, how? Thank you.

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      The rows are indexed entries, so you can refer to them by their position. Suppose, for instance, that you want to compare items in the current row and the next row, the following code will do:

      DataTable tbl = myDataSet[0];
      for (int i = 0; i < tbl.Rows.Count - 1; i++)
      {
      if (tbl.Rows[i]["myColumn"] == tbl.Rows[i+1]["myColumn"])
      {
      // It's a match
      }
      }

      "WPF has many lovers. It's a veritable porn star!" - Josh Smith

      As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

      My blog | My articles | MoXAML PowerToys | Onyx

      1 Reply Last reply
      0
      • Y Yonathan1111

        Hi everybody, I have DataSet which is filled by a database table called "schedule". And I want to compare the values of specific columns that are found in different rows, is possible? If it is, how? Thank you.

        D Offline
        D Offline
        dan sh
        wrote on last edited by
        #3

        Apart from what has been replied, you can also use the DataTable.Select method. You can specify the column value there and all the rows having that value will be returned. Depends on the scenario, which approach you should go for.

        It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD

        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