none
Reload TableRow from Database with LoadDataRow RRS feed

  • Question

  • Hi,

    I'm working with DataSet, DataTable and DataRows.

    I have the situation that the DataTable is loaded from Database with a certain state. There can be thousands of rows in the DataTable.

    Meanwhile one row of this table was modified in database on disk. If I would modify this row in memory and would do an update, a DBConcurrencyException would be thrown.

    In my case, the modification was not done by another user who is also working with the same database, but by the running application itself in a background thread, which waits for information from other processes. So I know exactly which row was modified by its primary key.

    I found the method LoadDataRow() of the DataTable which perhaps do exactly what I want, but I haven't found out how.

    According to documentation one can use this method by updating an existing row or if the row cannot be identified by its primary key, a new row is created. In my case I want to use it for the first purpose. My intention is, that the rowfields in memory should be filled with the values from the changed row in database so that further modifications can be done without  a DBConcurrencyException.

    There are two overloads for this method, and for both the first parameter is an object array with columnvalues. The only important value in my case should be the primary key, to identify the row. All others should not be used. But in all my calling efforts, the rowvalues are overwritten with these passed values which I don't want. I want that the values of the row are updated with the values of the modified row in database, so exactly in the sense as the methodname suggests LOAD DATA ROW.

    So is there a way to call this method, and the rowvalues are set with those from the database row, and NOT with those I have passed by the first parameter ?
    Even if I set all values of the objectarry to null (except the primary key of course) all values of the row are set to null.

    Any helpful hints for my problem ?

    Tuesday, April 2, 2013 3:03 PM

Answers


  • Anyway, I'm wondering why it should not be possible to ask a certain row, either directly or through its table or set, to reassign its values with the current values from the database ?

    Is merging really the only way to achieve that ?

    1) datatables and datasets have no knowledge of their originating table; it's only the adapters that do

    2) there may be other ways, but the merge is the most 'elegant'. I use merging a lot because you can bind the table to your interface, and merge or clear+merge the data into the table at a later time.


    Regards, Nico

    pdfaid, my blog

    • Marked as answer by Fritz Bilda Friday, April 5, 2013 6:30 AM
    Wednesday, April 3, 2013 7:28 AM

All replies

  • You simply should not load so huge datatables in memory.

    Be aware all samples are for simplicity without a where clause in the select. But in normal live those are always there.


    Success
    Cor

    Tuesday, April 2, 2013 3:41 PM
  • Hi Fritz,

    what you need is to merge the record, with the preservechanges param set to true.

    see here: http://msdn.microsoft.com/en-us/library/aszytsd8.aspx



    Regards, Nico

    pdfaid, my blog

    Tuesday, April 2, 2013 3:52 PM
  • Hi Nico,

    I succeeded in using the Merge() method of the DataSet,

    Anyway, I'm wondering why it should not be possible to ask a certain row, either directly or through its table or set, to reassign its values with the current values from the database ?

    Is merging really the only way to achieve that ?

    Tuesday, April 2, 2013 5:17 PM

  • Anyway, I'm wondering why it should not be possible to ask a certain row, either directly or through its table or set, to reassign its values with the current values from the database ?

    Is merging really the only way to achieve that ?

    1) datatables and datasets have no knowledge of their originating table; it's only the adapters that do

    2) there may be other ways, but the merge is the most 'elegant'. I use merging a lot because you can bind the table to your interface, and merge or clear+merge the data into the table at a later time.


    Regards, Nico

    pdfaid, my blog

    • Marked as answer by Fritz Bilda Friday, April 5, 2013 6:30 AM
    Wednesday, April 3, 2013 7:28 AM