开发者

updating batches of data

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 th开发者_如何转开发en 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...


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜