System.Data.Common.DbCommandBuilder.RefreshSchema C# (CSharp) Method

RefreshSchema() public method

public RefreshSchema ( ) : void
return void
        public virtual void RefreshSchema()
        {
            _dbSchemaTable = null;
            _dbSchemaRows = null;
            _sourceColumnNames = null;
            _quotedBaseTableName = null;

            DbDataAdapter adapter = DataAdapter;
            if (null != adapter)
            {
                if (InsertCommand == adapter.InsertCommand)
                {
                    adapter.InsertCommand = null;
                }
                if (UpdateCommand == adapter.UpdateCommand)
                {
                    adapter.UpdateCommand = null;
                }
                if (DeleteCommand == adapter.DeleteCommand)
                {
                    adapter.DeleteCommand = null;
                }
            }
            DbCommand command;
            if (null != (command = InsertCommand))
            {
                command.Dispose();
            }
            if (null != (command = UpdateCommand))
            {
                command.Dispose();
            }
            if (null != (command = DeleteCommand))
            {
                command.Dispose();
            }
            InsertCommand = null;
            UpdateCommand = null;
            DeleteCommand = null;
        }

Usage Example

        public static Message Update(XmlReader xmlReader, DbConnection connection, string operationType, DbCommandBuilder commandBuilder, string action)
        {
            string baseSelect = commandBuilder.DataAdapter.SelectCommand.CommandText;
            var baseCommand = commandBuilder.GetUpdateCommand();
            var commandCache = new Dictionary<string, DbCommand>();

            int count = 0;

            while (xmlReader.ReadToFollowing("Pair", AdoNetAdapter.MESSAGENAMESPACE))
            {
                xmlReader.ReadToFollowing("Before", AdoNetAdapter.MESSAGENAMESPACE);

                var beforeValues = GetParameterValues(xmlReader.ReadSubtree(), baseCommand.Parameters);
                string beforeColumns = CreateColumnList(commandBuilder, beforeValues.Keys);

                xmlReader.ReadToFollowing("After", AdoNetAdapter.MESSAGENAMESPACE);

                var afterValues = GetParameterValues(xmlReader.ReadSubtree(), baseCommand.Parameters);
                string afterColumns = CreateColumnList(commandBuilder, afterValues.Keys);

                string columns = string.Format("B:{0}|A:{1}", beforeColumns, afterColumns);

                DbCommand command = null;

                if (commandCache.ContainsKey(columns))
                    command = commandCache[columns];
                else
                {
                    commandBuilder.DataAdapter.SelectCommand.CommandText = baseSelect.Replace("*", columns);
                    commandBuilder.RefreshSchema();

                    command = commandBuilder.GetUpdateCommand();

                    commandCache[columns] = command;
                }

                DbHelpers.SetSourceParameters(beforeValues, command.Parameters);
                DbHelpers.SetTargetParameters(afterValues, command.Parameters);

                count += command.ExecuteNonQuery();
            }

            return DbHelpers.CreateMessage(operationType, count, action);
        }
All Usage Examples Of System.Data.Common.DbCommandBuilder::RefreshSchema