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. Preserving row pointer across an database update via a datatable

Preserving row pointer across an database update via a datatable

Scheduled Pinned Locked Moved C#
databasealgorithmshelpquestionannouncement
7 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.
  • J Offline
    J Offline
    jrgrobinson
    wrote on last edited by
    #1

    I am doing an update to my database after adding a row to the data table. The TableAdapter uses the VS2005 generated INSERT command (the table has a lot of columns). The line is... DishVarTA.Update(CurrentStDishVarRow); where 'CurrentStDishVarRow' points to the row in the 'Added' state. My problem is that I want to use the row data after this statement to format and send off to some machinery. After the Update however 'CurrentStDishVarRow' points to an entirely different row. I think the INSERT statement in the TableAdapter is putting the new row in at the beginning of the table so the row indexing changes. Is there any way I could preserve the pointer, or is the only way to fill the table again and/or find it again? Done a lot of searching and haven't found much that covers this, does that mean preserving row pointers across updates is not 'de rigeur'? Thanks,

    W M J 3 Replies Last reply
    0
    • J jrgrobinson

      I am doing an update to my database after adding a row to the data table. The TableAdapter uses the VS2005 generated INSERT command (the table has a lot of columns). The line is... DishVarTA.Update(CurrentStDishVarRow); where 'CurrentStDishVarRow' points to the row in the 'Added' state. My problem is that I want to use the row data after this statement to format and send off to some machinery. After the Update however 'CurrentStDishVarRow' points to an entirely different row. I think the INSERT statement in the TableAdapter is putting the new row in at the beginning of the table so the row indexing changes. Is there any way I could preserve the pointer, or is the only way to fill the table again and/or find it again? Done a lot of searching and haven't found much that covers this, does that mean preserving row pointers across updates is not 'de rigeur'? Thanks,

      W Offline
      W Offline
      Wael Dalloul
      wrote on last edited by
      #2

      jrgrobinson wrote:

      DishVarTA.Update(CurrentStDishVarRow);

      This code will attempts to save changes in the indicated DataRow to the database. You can store the row before updating and then manipulate the new instance of required row. now to locate the row in the datatable before calling the update method for the dataadapter use one of this methods: string s = "primaryKeyValue"; DataRow foundRow = datatable.Rows.Find(s); DataRow[] foundRows; foundRows = datatable.Select("put filter expression ");

      J 1 Reply Last reply
      0
      • J jrgrobinson

        I am doing an update to my database after adding a row to the data table. The TableAdapter uses the VS2005 generated INSERT command (the table has a lot of columns). The line is... DishVarTA.Update(CurrentStDishVarRow); where 'CurrentStDishVarRow' points to the row in the 'Added' state. My problem is that I want to use the row data after this statement to format and send off to some machinery. After the Update however 'CurrentStDishVarRow' points to an entirely different row. I think the INSERT statement in the TableAdapter is putting the new row in at the beginning of the table so the row indexing changes. Is there any way I could preserve the pointer, or is the only way to fill the table again and/or find it again? Done a lot of searching and haven't found much that covers this, does that mean preserving row pointers across updates is not 'de rigeur'? Thanks,

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        You are using the built in wizard thingys to do your data processing and now you want to do something slightly different to the STANDARD methedology, like post processing after an insert. This is why they are a POS, I strongly suggest you read up on Data Access Layer and rework all your data processing. As that is probably going to frighten the day lights out of you (as it would most people) try and capture the row information prior to saving back to the database (take a copy/clone of CurrentStDishVarRow) and see if you can work with that.

        Never underestimate the power of human stupidity RAH

        J 1 Reply Last reply
        0
        • M Mycroft Holmes

          You are using the built in wizard thingys to do your data processing and now you want to do something slightly different to the STANDARD methedology, like post processing after an insert. This is why they are a POS, I strongly suggest you read up on Data Access Layer and rework all your data processing. As that is probably going to frighten the day lights out of you (as it would most people) try and capture the row information prior to saving back to the database (take a copy/clone of CurrentStDishVarRow) and see if you can work with that.

          Never underestimate the power of human stupidity RAH

          J Offline
          J Offline
          jrgrobinson
          wrote on last edited by
          #4

          I guess this is the problem with the 'standard methodology'. It is kinda hard comining into it to understand the conventions. There certainly isn't a lot except experience that would tell you an update rearranges the cache. A view from other worlds would be that a data cache wouldn't change after a write to the source, thus preserving some independance between the user and source. Been doing a lot of reading and SQLCommands are looking attractive, but copying across the database update will get my machines working tomorrow. Thanks for taking the time to respond.

          1 Reply Last reply
          0
          • W Wael Dalloul

            jrgrobinson wrote:

            DishVarTA.Update(CurrentStDishVarRow);

            This code will attempts to save changes in the indicated DataRow to the database. You can store the row before updating and then manipulate the new instance of required row. now to locate the row in the datatable before calling the update method for the dataadapter use one of this methods: string s = "primaryKeyValue"; DataRow foundRow = datatable.Rows.Find(s); DataRow[] foundRows; foundRows = datatable.Select("put filter expression ");

            J Offline
            J Offline
            jrgrobinson
            wrote on last edited by
            #5

            Thanks. Just a simple question, after the update, could I assume the rows are all still in the TableAdapter and do the Find or Select then? Thanks

            W 1 Reply Last reply
            0
            • J jrgrobinson

              Thanks. Just a simple question, after the update, could I assume the rows are all still in the TableAdapter and do the Find or Select then? Thanks

              W Offline
              W Offline
              Wael Dalloul
              wrote on last edited by
              #6

              TableAdapter don't store any rows, it just provide communication between your application and a database. try to read this article to get more info:http://msdn.microsoft.com/en-us/library/bz9tthwx(VS.80).aspx[^] The Datatable represents one table of data, so you should depend on the datatable to use the find or select methods.

              Like what you do if you can't do what you like :)

              1 Reply Last reply
              0
              • J jrgrobinson

                I am doing an update to my database after adding a row to the data table. The TableAdapter uses the VS2005 generated INSERT command (the table has a lot of columns). The line is... DishVarTA.Update(CurrentStDishVarRow); where 'CurrentStDishVarRow' points to the row in the 'Added' state. My problem is that I want to use the row data after this statement to format and send off to some machinery. After the Update however 'CurrentStDishVarRow' points to an entirely different row. I think the INSERT statement in the TableAdapter is putting the new row in at the beginning of the table so the row indexing changes. Is there any way I could preserve the pointer, or is the only way to fill the table again and/or find it again? Done a lot of searching and haven't found much that covers this, does that mean preserving row pointers across updates is not 'de rigeur'? Thanks,

                J Offline
                J Offline
                jrgrobinson
                wrote on last edited by
                #7

                Just to close it off for prosperity. I have a data table, filled by a table adapter with '...WHERE(PK=@PK)'. It had a single row in it. I added another row (.NewRow, .AddRow). The Rows count of the table was 2. Index [0] pointed to the old origional data. Index [1] pointed to the new data, DataRowState=Added. I then called the table adapter.update (a rather large INSERT statement) There was still a count of two rows but both [0] and [1] pointed to the same row, the origional. This would indicate the data table of the dataset is no longer valid after an Update. I then did another fill and the data table had both rows as before (now unchanged state). The reason for writing this is to record for other people that may fall into this minor but time consuming trap. The tableAdapter.Update call is the end of the road for the validity of the data table data. There isn't a lot of documentation or web resource that tells you this. It maybe obvious to seasoned .NET database engineers, and maybe standard practice. It would be unexpected to new entrants in this field with experience of other, dare I say it, more normal, caching systems. Thanks for the help. Ooops, I modified Table Adapter to refer more correctly to the data table of the dataset where referring to storage.

                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