Get the last added row and modify its values... RRS feed

  • Question

  • Hi

    This is my code...





    string commandText = "INSERT INTO INFORMATION (ID, NAME) VALUES (10, RowName)";
    // I am creating the insert query for adapter here.
    // Executing query
    DataRow row = GetLatestRowAdded();// Get the latest row added in the adpter table
    return row;//return the row.

    I want to use this newly modified row reference at some other place in my code... With this reference i can modify the dataadpter table row values... and call dataAdapter's 'Update' method to save the modified values in the DataBase... Is it possible...? 

    And my 2nd question is -:
    How i can get the latest added row in the DataAdpter table...?
    Which is quickest way to do it...?
    (Getting last row from adpater table using 'rowCount - 1' is quickest ...?)

    I am using VS2005, C# and ACCESS 2007.

    Thanks in advance,

    • Edited by IamHuM Saturday, January 9, 2010 6:51 AM More info added.
    Saturday, January 9, 2010 6:50 AM


  • I'm not 100% sure what you're asking, but I think the answer to both your questions is "yes".

    1) Yes, you should be able to use the returned DataRow and any modifications you do to it should be able to be updated with your DataAdapter.

    2) Yes, using DataTable.Rows.Count -1 to get the last row in the DataTable is probably ok too.

    Although, without knowing what code you've got in the GetLatestRowAdded() method and not knowing how you're persisting your DataSet, I can only speculate. You might need to try it and see if it does what you want, and if it doesn't, post some more code.
    ~~Bonnie Berent [C# MVP]
    Wednesday, January 13, 2010 12:15 AM