System.Data.Merger.MergeTable C# (CSharp) Method

MergeTable() private method

private MergeTable ( DataTable src, DataTable dst ) : void
src DataTable
dst DataTable
return void
        private void MergeTable(DataTable src, DataTable dst)
        {
            int rowsCount = src.Rows.Count;
            bool wasEmpty = dst.Rows.Count == 0;
            if (0 < rowsCount)
            {
                Index ndxSearch = null;
                DataKey key = default(DataKey);
                dst.SuspendIndexEvents();
                try
                {
                    if (!wasEmpty && dst._primaryKey != null)
                    {
                        key = GetSrcKey(src, dst);
                        if (key.HasValue)
                        {
                            ndxSearch = dst._primaryKey.Key.GetSortIndex(DataViewRowState.OriginalRows | DataViewRowState.Added);
                        }
                    }

                    // this improves performance by iterating over the rows instead of computing their position
                    foreach (DataRow sourceRow in src.Rows)
                    {
                        DataRow targetRow = null;
                        if (ndxSearch != null)
                        {
                            targetRow = dst.FindMergeTarget(sourceRow, key, ndxSearch);
                        }
                        dst.MergeRow(sourceRow, targetRow, _preserveChanges, ndxSearch);
                    }
                }
                finally
                {
                    dst.RestoreIndexEvents(true);
                }
            }
            MergeExtendedProperties(src.ExtendedProperties, dst.ExtendedProperties);
        }

Same methods

Merger::MergeTable ( DataTable src ) : void

Usage Example

Esempio n. 1
0
        public void Merge(DataTable table, bool preserveChanges, MissingSchemaAction missingSchemaAction)
        {
            IntPtr hscp;
            Bid.ScopeEnter(out hscp, "<ds.DataTable.Merge|API> %d#, table=%d, preserveChanges=%d{bool}, missingSchemaAction=%d{ds.MissingSchemaAction}\n", ObjectID, (table != null) ? table.ObjectID : 0, preserveChanges, (int)missingSchemaAction);
            try{
                if (table == null)
                    throw ExceptionBuilder.ArgumentNull("table");

                switch(missingSchemaAction) { // @perfnote: Enum.IsDefined
                case MissingSchemaAction.Add:
                case MissingSchemaAction.Ignore:
                case MissingSchemaAction.Error:
                case MissingSchemaAction.AddWithKey:
                    Merger merger = new Merger(this, preserveChanges, missingSchemaAction);
                    merger.MergeTable(table);
                    break;
                default:
                    throw Common.ADP.InvalidMissingSchemaAction(missingSchemaAction);
                }
            }
            finally{
                Bid.ScopeLeave(ref hscp);
            }
        }
All Usage Examples Of System.Data.Merger::MergeTable