GetInsertCommand() public method

public GetInsertCommand ( ) : DbCommand
return DbCommand
示例#1
0
 System.Data.Common.DbCommand CreateInsertCommand()
 {
     if (_commandBuilder == null)
     {
         CreateDataAdapter();
     }
     return(_commandBuilder.GetInsertCommand(true));
 }
        public static Message Create(XmlReader xmlReader, DbConnection connection, string operationType, DbCommandBuilder commandBuilder, string action)
        {
            int count = 0;

            string baseSelect = commandBuilder.DataAdapter.SelectCommand.CommandText;
            var baseCommand = commandBuilder.GetInsertCommand();
            var commandCache = new Dictionary<string, DbCommand>();

            while (xmlReader.ReadToFollowing("Row", AdoNetAdapter.MESSAGENAMESPACE))
            {
                var values = GetParameterValues(xmlReader.ReadSubtree(), baseCommand.Parameters);
                string columns = CreateColumnList(commandBuilder, values.Keys);

                DbCommand command = null;

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

                    command = commandBuilder.GetInsertCommand();

                    commandCache[columns] = command;
                }

                DbHelpers.SetTargetParameters(values, command.Parameters);

                count += command.ExecuteNonQuery();
            }

            return DbHelpers.CreateMessage(operationType, count, action);
        }