Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi,
Rightnow the solution we are using in which there is datatable displayed via dataset on webpage..When page loads this table will be by default at that page...and there is one button called as save button..this data table user can edit...and when the user press the save button with out making any changes in datatable it will run a stored procedure and update the result to database table still if users havent made any of changes...
 
Now here is the problem part :::
now the user requirements is like this they want to update in database only those rows , whose contents has been changed ..NOT OF EACH AND EVERY ROW....
 
according to me if i compare the content of data table on webpage with sql servers database table..and if contents are different only then i can run stored procedure which in turn update the database...But how can I do this..I need help very urgently...
 

Thanks
Posted 14-Jan-13 12:00pm
jstu266310

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

DataTable has a method called GetChanges which returns all changes made to the table after the last AcceptChanges is called.
 
see here[^] for more
[Code sample]
private void UpdateDataTable(DataTable table, 
    OleDbDataAdapter myDataAdapter)
{
    DataTable xDataTable = table.GetChanges();
 
    // Check the DataTable for errors. 
    if (xDataTable.HasErrors)
    {
        // Insert code to resolve errors.
    }
 
    // After fixing errors, update the database with the DataAdapter 
    myDataAdapter.Update(xDataTable);
}
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 330
1 Maciej Los 180
2 Richard MacCutchan 115
3 arvind mepani 104
4 Tino Fourie 92


Advertise | Privacy | Mobile
Web03 | 2.8.140709.1 | Last Updated 14 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid