コード例 #1
0
        /// <summary>
        /// Executes the respective command for each inserted, updated, or deleted row in the DataSet.
        /// </summary>
        /// <remarks>
        /// e.g.:  
        ///  UpdateDataset(conn, insertCommand, deleteCommand, updateCommand, dataSet, "Order");
        /// </remarks>
        /// <param name="insertCommand">A valid transact-SQL statement to insert new records into the data source</param>
        /// <param name="deleteCommand">A valid transact-SQL statement to delete records from the data source</param>
        /// <param name="updateCommand">A valid transact-SQL statement used to update records in the data source</param>
        /// <param name="dataSet">The DataSet used to update the data source</param>
        /// <param name="tableName">The DataTable used to update the data source.</param>
        public static void UpdateDataset(AsaCommand insertCommand, AsaCommand deleteCommand, AsaCommand updateCommand, DataSet dataSet, string tableName)
        {
            if( insertCommand == null ) throw new ArgumentNullException( "insertCommand" );
            if( deleteCommand == null ) throw new ArgumentNullException( "deleteCommand" );
            if( updateCommand == null ) throw new ArgumentNullException( "updateCommand" );
            if( tableName == null || tableName.Length == 0 ) throw new ArgumentNullException( "tableName" );

            // Create a AsaDataAdapter, and dispose of it after we are done
            AsaDataAdapter dataAdapter = new AsaDataAdapter();
            try
            {
                // Set the data adapter commands
                dataAdapter.UpdateCommand = updateCommand;
                dataAdapter.InsertCommand = insertCommand;
                dataAdapter.DeleteCommand = deleteCommand;

                // Update the dataset changes in the data source
                dataAdapter.Update (dataSet,tableName);

                // Commit all the changes made to the DataSet
                dataSet.AcceptChanges();
            }
            catch (AsaException E)
            {string strError=E.Message;}
            finally{dataAdapter.Dispose();}
        }