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

RowUpdatingHandler() protected method

protected RowUpdatingHandler ( RowUpdatingEventArgs rowUpdatingEvent ) : void
rowUpdatingEvent RowUpdatingEventArgs
return void
        protected void RowUpdatingHandler(RowUpdatingEventArgs rowUpdatingEvent)
        {
            if (null == rowUpdatingEvent)
            {
                throw ADP.ArgumentNull(nameof(rowUpdatingEvent));
            }
            try
            {
                if (UpdateStatus.Continue == rowUpdatingEvent.Status)
                {
                    StatementType stmtType = rowUpdatingEvent.StatementType;
                    DbCommand command = (DbCommand)rowUpdatingEvent.Command;

                    if (null != command)
                    {
                        switch (stmtType)
                        {
                            case StatementType.Select:
                                Debug.Assert(false, "how did we get here?");
                                return; // don't mess with it
                            case StatementType.Insert:
                                command = InsertCommand;
                                break;
                            case StatementType.Update:
                                command = UpdateCommand;
                                break;
                            case StatementType.Delete:
                                command = DeleteCommand;
                                break;
                            default:
                                throw ADP.InvalidStatementType(stmtType);
                        }

                        if (command != rowUpdatingEvent.Command)
                        {
                            command = (DbCommand)rowUpdatingEvent.Command;
                            if ((null != command) && (null == command.Connection))
                            {
                                DbDataAdapter adapter = DataAdapter;
                                DbCommand select = ((null != adapter) ? adapter.SelectCommand : null);
                                if (null != select)
                                {
                                    command.Connection = select.Connection;
                                }
                            }
                            // user command, not a command builder command
                        }
                        else command = null;
                    }
                    if (null == command)
                    {
                        RowUpdatingHandlerBuilder(rowUpdatingEvent);
                    }
                }
            }
            catch (Exception e) when (ADP.IsCatchableExceptionType(e))
            {
                ADP.TraceExceptionForCapture(e);
                rowUpdatingEvent.Status = UpdateStatus.ErrorsOccurred;
                rowUpdatingEvent.Errors = e;
            }
        }