Click here to Skip to main content
15,891,621 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In Datagridview if we update any data that should be stored in that database table.But i want the updated row should be stored in another Table.

I am doing one project everytime we updated data that should be stored related to that table but in my project i want to show only updated data should be shown in print preview so for that purpose we have to store that updated data in another table and my code for update is

C#
try
           {
               oledbCmdBuilder = new OleDbCommandBuilder(oledbAdapter);
               changes = ds.GetChanges();
               if (changes == null)
               {
                   MessageBox.Show("Please edit something and click update button");
                   return;
               }
               if (changes != null)
               {
                   oledbAdapter.Update(ds.Tables[0]);
               }
               ds.AcceptChanges();
               MessageBox.Show("Record added successfully");
           }
           catch (Exception ex)
           {
               MessageBox.Show(ex.ToString());
           }
Posted
Updated 1-Oct-13 23:22pm
v3
Comments
Akinmade Bond 2-Oct-13 4:17am    
What have you tried? Your code...
sreelatha kuruba 2-Oct-13 4:22am    
Sir,Actually iam doing one project everytime we updated data that should be stored related to that table but in my project i want to show only updated data should be shown in print preview so for that purpose we have to store that updated data in another table and my code for update is


try
{
oledbCmdBuilder = new OleDbCommandBuilder(oledbAdapter);
changes = ds.GetChanges();
if (changes == null)
{
MessageBox.Show("Please edit something and click update button");
return;
}
if (changes != null)
{
oledbAdapter.Update(ds.Tables[0]);
}
ds.AcceptChanges();
MessageBox.Show("Record added successfully");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
Sergey Alexandrovich Kryukov 2-Oct-13 4:24am    
Not a question.
—SA

1 solution

Basically for such a situation where you need to insert/update data to a different table, you cannot use the Accept Changes API's as these in built API's work on the base table.

What can be done is catch the apprpriate event and inside that event access the table you desire for insert/update.

-SP
 
Share this answer
 
Comments
sreelatha kuruba 2-Oct-13 6:17am    
THANKYOU FOR GIVING ME SOLUTION SIR

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900