none
how do I get UpdateAll to work RRS feed

  • Question

  •         /// <summary>
            ///Update all changes to the dataset.
            ///</summary>
            [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
            public virtual int UpdateAll(logbookds dataSet) {
                if ((dataSet == null)) {
                    throw new global::System.ArgumentNullException("dataSet");
                }
                //if ((dataSet.HasChanges() == false)) {
                //    return 0;
                //}
                if (((this._log_bookidTableAdapter != null) 
                            && (this.MatchTableAdapterConnection(this._log_bookidTableAdapter.Connection) == false))) {
                    throw new global::System.ArgumentException("All TableAdapters managed by a TableAdapterManager must use the same connection s" +
                            "tring.");
                }
                global::System.Data.IDbConnection workConnection = this.Connection;
                if ((workConnection == null)) {
                    throw new global::System.ApplicationException("TableAdapterManager contains no connection information. Set each TableAdapterMana" +
                            "ger TableAdapter property to a valid TableAdapter instance.");
                }
                bool workConnOpened = false;
                if (((workConnection.State & global::System.Data.ConnectionState.Broken) 
                            == global::System.Data.ConnectionState.Broken)) {
                    workConnection.Close();
                }
                if ((workConnection.State == global::System.Data.ConnectionState.Closed)) {
                    workConnection.Open();
                    workConnOpened = true;
                }
                global::System.Data.IDbTransaction workTransaction = workConnection.BeginTransaction();
                if ((workTransaction == null)) {
                    throw new global::System.ApplicationException("The transaction cannot begin. The current data connection does not support transa" +
                            "ctions or the current state is not allowing the transaction to begin.");
                }
                global::System.Collections.Generic.List<global::System.Data.DataRow> allChangedRows = new global::System.Collections.Generic.List<global::System.Data.DataRow>();
                global::System.Collections.Generic.List<global::System.Data.DataRow> allAddedRows = new global::System.Collections.Generic.List<global::System.Data.DataRow>();
                global::System.Collections.Generic.List<global::System.Data.Common.DataAdapter> adaptersWithAcceptChangesDuringUpdate = new global::System.Collections.Generic.List<global::System.Data.Common.DataAdapter>();
                global::System.Collections.Generic.Dictionary<object, global::System.Data.IDbConnection> revertConnections = new global::System.Collections.Generic.Dictionary<object, global::System.Data.IDbConnection>();
                int result = 0;
                global::System.Data.DataSet backupDataSet = null;
                if (this.BackupDataSetBeforeUpdate) {
                    backupDataSet = new global::System.Data.DataSet();
                    backupDataSet.Merge(dataSet);
                }
                try {
                    // ---- Prepare for update -----------
                    //
                    if ((this._log_bookidTableAdapter != null)) {
                        revertConnections.Add(this._log_bookidTableAdapter, this._log_bookidTableAdapter.Connection);
                        this._log_bookidTableAdapter.Connection = ((global::System.Data.SqlClient.SqlConnection)(workConnection));
                        this._log_bookidTableAdapter.Transaction = ((global::System.Data.SqlClient.SqlTransaction)(workTransaction));
                        if (this._log_bookidTableAdapter.Adapter.AcceptChangesDuringUpdate) {
                            this._log_bookidTableAdapter.Adapter.AcceptChangesDuringUpdate = false;
                            adaptersWithAcceptChangesDuringUpdate.Add(this._log_bookidTableAdapter.Adapter);
                        }
                    }
                    // 
                    //---- Perform updates -----------
                    //
                    if ((this.UpdateOrder == UpdateOrderOption.UpdateInsertDelete)) {
                        result = (result + this.UpdateUpdatedRows(dataSet, allChangedRows, allAddedRows));
                        result = (result + this.UpdateInsertedRows(dataSet, allAddedRows));
                    }
                    else {
                        result = (result + this.UpdateInsertedRows(dataSet, allAddedRows));
                        result = (result + this.UpdateUpdatedRows(dataSet, allChangedRows, allAddedRows));
                    }
                    result = (result + this.UpdateDeletedRows(dataSet, allChangedRows));
                    // 
                    //---- Commit updates -----------
                    //
                    workTransaction.Commit();
                    if ((0 < allAddedRows.Count)) {
                        global::System.Data.DataRow[] rows = new System.Data.DataRow[allAddedRows.Count];
                        allAddedRows.CopyTo(rows);
                        for (int i = 0; (i < rows.Length); i = (i + 1)) {
                            global::System.Data.DataRow row = rows[i];
                            row.AcceptChanges();
                        }
                    }
                    if ((0 < allChangedRows.Count)) {
                        global::System.Data.DataRow[] rows = new System.Data.DataRow[allChangedRows.Count];
                        allChangedRows.CopyTo(rows);
                        for (int i = 0; (i < rows.Length); i = (i + 1)) {
                            global::System.Data.DataRow row = rows[i];
                            row.AcceptChanges();
                        }
                    }
                }
                catch (global::System.Exception ex) {
                    workTransaction.Rollback();
                    // ---- Restore the dataset -----------
                    if (this.BackupDataSetBeforeUpdate) {
                        global::System.Diagnostics.Debug.Assert((backupDataSet != null));
                        dataSet.Clear();
                        dataSet.Merge(backupDataSet);
                    }
                    else {
                        if ((0 < allAddedRows.Count)) {
                            global::System.Data.DataRow[] rows = new System.Data.DataRow[allAddedRows.Count];
                            allAddedRows.CopyTo(rows);
                            for (int i = 0; (i < rows.Length); i = (i + 1)) {
                                global::System.Data.DataRow row = rows[i];
                                row.AcceptChanges();
                                row.SetAdded();
                            }
                        }
                    }
                    throw ex;
                }
                finally {
                    if (workConnOpened) {
                        workConnection.Close();
                    }
                    if ((this._log_bookidTableAdapter != null)) {
                        this._log_bookidTableAdapter.Connection = ((global::System.Data.SqlClient.SqlConnection)(revertConnections[this._log_bookidTableAdapter]));
                        this._log_bookidTableAdapter.Transaction = null;
                    }
                    if ((0 < adaptersWithAcceptChangesDuringUpdate.Count)) {
                        global::System.Data.Common.DataAdapter[] adapters = new System.Data.Common.DataAdapter[adaptersWithAcceptChangesDuringUpdate.Count];
                        adaptersWithAcceptChangesDuringUpdate.CopyTo(adapters);
                        for (int i = 0; (i < adapters.Length); i = (i + 1)) {
                            global::System.Data.Common.DataAdapter adapter = adapters[i];
                            adapter.AcceptChangesDuringUpdate = true;
                        }
                    }
                }
                return result;
            }
            
    This yields null value:
    global::System.Data.IDbConnection workConnection = this.Connection;
    in logbookds.designer.cs generated by a tool!
    • Moved by Jim Zhou - MSFT Monday, January 18, 2010 6:21 AM ADO.NET related forum (From:Windows Presentation Foundation (WPF))
    Sunday, January 10, 2010 10:38 PM

All replies

  • Hi Landon1,

    Since this is WPF forum, and your issue seems more like ADO.NET related issue, so I am moving this thread to ADO.NET forum.


    Thanks.
    Sincerely.


    Jim Zhou -MSFT
    Monday, January 18, 2010 6:20 AM
  • NOT an ado issue!!!   the ado section will have trouble with WPF

    did you have trouble setting up the data base
    . I could have helped you set it up in minutes.

    The problem is WPF and only WPF!!
    • Edited by landon1 Monday, January 18, 2010 3:41 PM added
    Monday, January 18, 2010 3:39 PM
  • Hi landon1 ,

    Sorry for misunderstanding.
    Since this is WPF related issue, could you kindly provide a simplified sample for us to reproduce? so that we can quickly focus on the issue.

    Thanks.
    Sincerely.


    Jim Zhou -MSFT
    Wednesday, January 20, 2010 12:15 PM
  • pass...just delete the thread...you can do that can't you
    Wednesday, January 20, 2010 4:10 PM