How to copy Modified Records In a DataSet to another Dataset??
I have created a dataset from database "DB1" table "T_DB1". I Loop throw the Dataset and make changes/modification tosome of the records. After that I try to update the Dataset.
Lets say the update fails because database is down. I would like to create a backup of the modified data in a different database so I can load it manually latter on in the real database.
I am currently going throw every row of the dataset and finding what has been modified and the inserting that record into the backup database.
... BUT Is there any better way of doing this?This forum is falling appart. Its not like it used to be.
There is a way to do this.
You simply have to dynamically change your SQL statement and connection.
Eg. If your using a SqlDataAdapter, just change the update command associated with it and set it's connection property to the new database. All rows that have been updated will call this function which will update your backup database... I would look something like this:
Try
'Update database (main database)Catch ex as Exception
'Check exception, if database is down then...
newConnectionString = new sqlConnection(".....")
mySqlDataAdapter.UpdateCommand = new sqlcommand(newConnectionString)
UpdateCommand.commandtext = ".............."'Update backup database
End Try
Thats right. Thanks
Labels: ado, copy, created, database, dataset, db1, loop, modification, modified, net, records, t_db1, table, throw, tosome
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home