About DataSet transaction processing and SqlDataAdapter usage, sqldataadapter usage
If the SQL statement is executed directly, the transaction is well processed. For most Erp applications, SQL cannot be used to process data. Therefore, it is more common to update DataSet and update a single DataSet, no transaction processing is required. Adding transactions to multiple DataSet is mostly used in distributed program code. The following is the transaction processing code for updating the compressed DataSet passed by Winform in Webservice, multiple DataSet.
/// <Summary> /// update the compressed DataSet // </summary> /// <param> environment variable </param> /// <param> binary dataSet </param> /// <returns> has an exception, returns an error message </returns> public object UpdataSet (object [] env, byte [] byt) {object info = null; SqlConnection sqlconn = null; // define the transaction SqlTransaction transaction = null; DataSet ds = null; try {ds = md. bytesToDs (byt); string Url = "database connection language name"; sqlconn = new SqlConnection (Url); sqlconn. Open (); transaction = sqlconn. beginTransaction (IsolationLevel. readCommitted, "transname"); // instantiate the transaction SqlDataAdapter adapter; SqlCommandBuilder objCommandBuilder; for (int I = 0; I <ds. tables. count; I ++) {adapter = new SqlDataAdapter ("select * from" + ds. tables [I]. tableName + "where 2> 3", sqlconn); // traditional usage objCommandBuilder = new SqlCommandBuilder (adapter); // start to suspend/suspend the operation adapter. deleteCommand = new SqlCommand ("... delete statement .. ", sqlconn, transaction); // The addition, query, modification, and deletion of the adapter can be used with the transaction. Note that there is no instance SqlCommand object, so the new SqlCommand adapter. insertCommand = new SqlCommand ("............ ", sqlconn, transaction); adapter. updateCommand = new SqlCommand ("............. ", sqlconn, transaction); adapter. selectCommand = new SqlCommand ("select * from" + ds. tables [I]. tableName + "where 2> 3", sqlconn, transaction); // The new usage of adapter, After new SqlCommand, write SQL statements and SqlConnection. You can also write transactions... you do not need to use the instance SqlCommand object // you do not need to use the instance SqlCommand object to obtain the adapter. deleteCommand = objCommandBuilder. getDeleteCommand (); adapter. insertCommand = objCommandBuilder. getInsertCommand (); adapter. updateCommand = objCommandBuilder. getUpdateCommand (); objCommandBuilder. dataAdapter. update (ds, ds. tables [I]. tableName. toString (); //} transaction. commit (); // submit the transaction sqlconn. close ();} Catch (Exception err) {Console. out. writeLine ("An error occurred while saving the disk:" + err. message); info = "An error occurred while saving the disk:" + err. message; // transaction rollback transaction. rollback ();} finally {if (sqlconn! = Null) {sqlconn. Close () ;}} return info ;}