System.Data.DataTable.BeginLoadData C# (CSharp) Method

BeginLoadData() public method

public BeginLoadData ( ) : void
return void
        public void BeginLoadData()
        {
            long logScopeId = DataCommonEventSource.Log.EnterScope("<ds.DataTable.BeginLoadData|API> {0}", ObjectID);
            try
            {
                if (_inDataLoad)
                {
                    return;
                }

                _inDataLoad = true;
                Debug.Assert(null == _loadIndex, "loadIndex should already be null");
                _loadIndex = null;

                // LoadDataRow may have been called before BeginLoadData and already
                // initialized loadIndexwithOriginalAdded & loadIndexwithCurrentDeleted 

                _initialLoad = (Rows.Count == 0);
                if (_initialLoad)
                {
                    SuspendIndexEvents();
                }
                else
                {
                    if (_primaryKey != null)
                    {
                        _loadIndex = _primaryKey.Key.GetSortIndex(DataViewRowState.OriginalRows);
                    }
                    if (_loadIndex != null)
                    {
                        _loadIndex.AddRef();
                    }
                }

                if (DataSet != null)
                {
                    _savedEnforceConstraints = DataSet.EnforceConstraints;
                    DataSet.EnforceConstraints = false;
                }
                else
                {
                    EnforceConstraints = false;
                }
            }
            finally
            {
                DataCommonEventSource.Log.ExitScope(logScopeId);
            }
        }

Usage Example

Example #1
0
        public static DataSet DataReaderToDataSet(IDataReader reader)
        {
            var ds = new DataSet();
            DataTable table;
            do
            {
                int fieldCount = reader.FieldCount;
                table = new DataTable();
                for (int i = 0; i < fieldCount; i++)
                {
                    table.Columns.Add(reader.GetName(i), reader.GetFieldType(i));
                }
                table.BeginLoadData();
                var values = new Object[fieldCount];
                while (reader.Read())
                {
                    reader.GetValues(values);
                    table.LoadDataRow(values, true);
                }
                table.EndLoadData();

                ds.Tables.Add(table);

            } while (reader.NextResult());
            reader.Close();
            return ds;
        }
All Usage Examples Of System.Data.DataTable::BeginLoadData
DataTable