GetUpdateCommand() public method

public GetUpdateCommand ( ) : DbCommand
return DbCommand
示例#1
0
 System.Data.Common.DbCommand CreateUpdateCommand()
 {
     if (_commandBuilder == null)
     {
         CreateDataAdapter();
     }
     return(_commandBuilder.GetUpdateCommand(true));
 }
        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);
        }
示例#3
0
 /// <summary>
 /// Creates the update command for the database update operations of the recordset
 /// </summary>
 /// <param name="adapter">The data adapter that will contain the update command</param>
 /// <param name="cmdBuilder">The command builder to get the update command from.</param>
 protected virtual void CreateUpdateCommand(DbDataAdapter adapter, DbCommandBuilder cmdBuilder)
 {
     try
     {
         adapter.UpdateCommand = (string.IsNullOrEmpty(sqlUpdateQuery)) ? cmdBuilder.GetUpdateCommand(true) : CreateCommand(sqlUpdateQuery, CommandType.Text, null);
     }
     catch (Exception)
     {
         adapter.UpdateCommand = CreateUpdateCommandFromMetaData();
     }
 }