Esempio n. 1
0
        /// <summary>
        /// Method that uploads the data from the <see cref="System.Data.DataTable">DataTable</see> that contains the data.
        /// </summary>
        /// <param name="table">Data table that contains source data that to be uploaded</param>
        public void Upload(System.Data.DataTable table)
        {
            CommonFunctions functions = new CommonFunctions();
            string sql = "";
            int counter = 0;
            BatchSizeCompletedEventArgs eventArgs = new BatchSizeCompletedEventArgs();
            eventArgs.ErrorDataRows = new List<System.Data.DataRow>();
            foreach (System.Data.DataRow item in table.Rows)
            {
                try
                {
                    // SQL constructed. 
                    // Using the destination connection Execute the statement
                    sql = functions.ConstructSql(DestinationTableName, item, ColumnMapItems);
                    Console.WriteLine(sql);
                    MySqlCommand command = new MySqlCommand(sql, DestinationDbConnection);
                    command.ExecuteNonQuery();
                }
                catch (Exception)
                {
                    eventArgs.ErrorDataRows.Add(item);
                }
                
                counter++;

                /*
                 * Issue 2:	Does not support Batch sizes like in SqlBulkCopy
                 * When the bulkupload code uploads the batch size that is specified by the caller, we need to notify the caller that
                 * The batch size is done uploading. This will help the caller to make their decisions.
                 */
                if (counter == BatchSize && counter > 0)
                {
                    // batch size is completed. invoke the OnBatchSizeCompletedDelegate to alert the caller
                    if (OnBatchSizeCompleted != null)
                    {
                        // create the event arguments
                        
                        eventArgs.CompletedRows = counter.ToString();
                        // invoke the delegate
                        OnBatchSizeCompleted(eventArgs);
                    }
                    eventArgs.CompletedRows = "";
                    eventArgs.ErrorDataRows.Clear();
                    counter = 0;
                }
            }

            // A final raise from the code. this is to catch the arbitary values that does not meet the batch size limit
            if (counter > 0)
            {
                // batch size is completed. invoke the OnBatchSizeCompletedDelegate to alert the caller
                if (OnBatchSizeCompleted != null)
                {
                    // create the event arguments
                    eventArgs.CompletedRows = counter.ToString();
                    // invoke the delegate
                    OnBatchSizeCompleted(eventArgs);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Method that uploads the data from the <see cref="System.Data.DataTable">DataTable</see> that contains the data.
        /// </summary>
        /// <param name="table">Data table that contains source data that to be uploaded</param>
        public void Upload(System.Data.DataTable table)
        {
            CommonFunctions             functions = new CommonFunctions();
            string                      sql       = "";
            int                         counter   = 0;
            BatchSizeCompletedEventArgs eventArgs = new BatchSizeCompletedEventArgs();

            eventArgs.ErrorDataRows = new List <System.Data.DataRow>();
            foreach (System.Data.DataRow item in table.Rows)
            {
                try
                {
                    // SQL constructed.
                    // Using the destination connection Execute the statement
                    sql = functions.ConstructSql(DestinationTableName, item, ColumnMapItems);
                    Console.WriteLine(sql);
                    MySqlCommand command = new MySqlCommand(sql, DestinationDbConnection);
                    command.ExecuteNonQuery();
                }
                catch (Exception)
                {
                    eventArgs.ErrorDataRows.Add(item);
                }

                counter++;

                /*
                 * Issue 2:	Does not support Batch sizes like in SqlBulkCopy
                 * When the bulkupload code uploads the batch size that is specified by the caller, we need to notify the caller that
                 * The batch size is done uploading. This will help the caller to make their decisions.
                 */
                if (counter == BatchSize && counter > 0)
                {
                    // batch size is completed. invoke the OnBatchSizeCompletedDelegate to alert the caller
                    if (OnBatchSizeCompleted != null)
                    {
                        // create the event arguments

                        eventArgs.CompletedRows = counter.ToString();
                        // invoke the delegate
                        OnBatchSizeCompleted(eventArgs);
                    }
                    eventArgs.CompletedRows = "";
                    eventArgs.ErrorDataRows.Clear();
                    counter = 0;
                }
            }

            // A final raise from the code. this is to catch the arbitary values that does not meet the batch size limit
            if (counter > 0)
            {
                // batch size is completed. invoke the OnBatchSizeCompletedDelegate to alert the caller
                if (OnBatchSizeCompleted != null)
                {
                    // create the event arguments
                    eventArgs.CompletedRows = counter.ToString();
                    // invoke the delegate
                    OnBatchSizeCompleted(eventArgs);
                }
            }
        }