Example #1
0
        public void Read(CancellationToken cancellationToken, IProgress <DataRow> progress)
        {
            Action <DbDataReader> action = reader =>
            {
                try
                {
                    var x = new DbReader(reader);
                    x.ReadTable(cancellationToken, progress);
                }
                catch (Exception ex)
                {
                    OnError(new SqlExceptionEventArgs(command, ex));
                }
            };

            Read(action);
        }
Example #2
0
        public int CopyTo(TableName tname2, SqlBulkCopyColumnMapping[] mappings, CancellationToken cancellationToken, IProgress <int> progress)
        {
            DataTable table = new DataTable();
            int       step  = 0;

            Action <DbDataReader> copy = reader =>
            {
                var dbReader = new DbReader(reader);
                table = DbReader.CreateTable(reader);

                DataRow row;

                while (reader.Read())
                {
                    step++;

                    if (step % 19 == 0)
                    {
                        progress?.Report(step);
                    }

                    row = dbReader.ReadRow(table);
                    table.Rows.Add(row);

                    if (step % MaxRowCount == 0)
                    {
                        BulkCopy(table, tname2, mappings);
                    }

                    if (cancellationToken.IsCancellationRequested)
                    {
                        break;
                    }
                }

                if (step % MaxRowCount != 0)
                {
                    BulkCopy(table, tname2, mappings);
                }
            };

            tableReader.cmd.Read(copy);

            return(step);
        }
Example #3
0
        /// <summary>
        /// Fill data table by DbDataReader
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <param name="progress"></param>
        /// <returns></returns>
        public DataTable ReadDataTable(CancellationToken cancellationToken, IProgress <int> progress)
        {
            DataTable table = null;

            Action <DbDataReader> action = reader =>
            {
                try
                {
                    table = new DbReader(reader).ReadTable(cancellationToken, progress);
                }
                catch (Exception ex)
                {
                    OnError(new SqlExceptionEventArgs(command, ex));
                }
            };

            Read(action);

            return(table);
        }