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. Update a DataRow in a DataTable;

Update a DataRow in a DataTable;

Scheduled Pinned Locked Moved C#
questionannouncement
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.
  • S Offline
    S Offline
    swjam
    wrote on last edited by
    #1

    Hi I just wanted to know the proper way of updating a DataRow. If I have a DataTable say locDTable which already has rows populated through Iterate { DataRow locDRow = locDTable.NewRow(); //Put DataRow values here locDTable.Rows.Add(locDRow); } How do I access (and modify a particular column entry for a particular row? The way I would do it something like: locDTable.Rows[rowIndex][colIndex] = newValue; Is this the proper way? Thank you in advance! j11Software

    I 1 Reply Last reply
    0
    • S swjam

      Hi I just wanted to know the proper way of updating a DataRow. If I have a DataTable say locDTable which already has rows populated through Iterate { DataRow locDRow = locDTable.NewRow(); //Put DataRow values here locDTable.Rows.Add(locDRow); } How do I access (and modify a particular column entry for a particular row? The way I would do it something like: locDTable.Rows[rowIndex][colIndex] = newValue; Is this the proper way? Thank you in advance! j11Software

      I Offline
      I Offline
      il_masacratore
      wrote on last edited by
      #2

      Hi Maybe, instead of access to the column by an index you can use strings constants to access to columns. It seems more elegant and if you change the structure of the table the acces to the previous column doesn't change. To access to a particular row the only way is by an index.

      S 1 Reply Last reply
      0
      • I il_masacratore

        Hi Maybe, instead of access to the column by an index you can use strings constants to access to columns. It seems more elegant and if you change the structure of the table the acces to the previous column doesn't change. To access to a particular row the only way is by an index.

        S Offline
        S Offline
        SpartanSoft
        wrote on last edited by
        #3

        I agree 100% with the constants approach for column names, we do that all the time here and has paid of on numerous occasions. We also do it for the table names. It decouples you from Database especially for column name changes (just change constant literal) as well as makes the code much more readable.

        Christopher Pond Innovative Technology Solutions SpartanSoft.net.

        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