views:

18

answers:

2

I am using GridView in asp .net and editing data with edit command field property (as we know after updating the edited row, we automatically update the database), and I want to use transactions (with begin to commit statement - including rollback) to commit this update query in database, after clicking in some button (after some events for example), not automatically to insert or update the edited data from grid directly to the DB...so I want to save them somewhere temporary (even many edited rows - not just one row) and then to confirm the transaction - to update the real tables in database...

Any suggestions are welcomed...

I've used some good links, but very helpful, like: http://www.asp.net/learn/data-access/tutorial-63-cs.aspx http://www.asp.net/learn/data-access/tutorial-66-cs.aspx etc...

+1  A: 

First way: Create session variable that will contain your DB object (DataTable or mapped objects). The GridView should work with this instance instead of sending the data to the database. Once editing is finished you may take the object from the session and save it in the way you normally do.

Second way: I would use javascript to collect all changes on the client side while he is editing as a array of objects (each object is separate row). Once the editing done, you can create json string from the collection and pass it to the server. If your json object configuration is same as server class then you can use JavaScriptSerializer to deserialize your string into collection of object. After that, you can save your objects in the way you normally do.

Andrey Tagaew
Very clear explanations! For both ways I have solutions, and I accept as accepted answer, but unfortunately I already did before to first answer :)Thank you once again!
gaponte69
+1  A: 

Well,

you can store your edited data in a DataTable in session. and then pass this data table as a bulk insert in to the database. 2 options are available for this

  1. if you are using SQL Server 2005 you can use OpenXML to achieve this, as i have stated here
  2. if you are using SQL Server 2008 youc an use Table Variables like i did here.

i hope it helps

Aneef
Thank you for the suggestions, Aneef! Very helpful information...
gaponte69