Author: suresh
Date: 2005-03-22 05:58:48 -0500 (Tue, 22 Mar 2005)
New Revision: 42094

Modified:
   trunk/mcs/class/System.Data/System.Data.Common/ChangeLog
   trunk/mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs
Log:
2005-03-22  Sureshkumar T  <[EMAIL PROTECTED]>

        * DbDataAdapter.cs: Update (): update the rows based on the
        UpdateRowSource property. Process further based on the
        RowUpdatedEvent handler argument's Status property.

        Fixes bug #73587. Thanks to [EMAIL PROTECTED] (Ingo Bauersachs) for
        bug report and patch.



Modified: trunk/mcs/class/System.Data/System.Data.Common/ChangeLog
===================================================================
--- trunk/mcs/class/System.Data/System.Data.Common/ChangeLog    2005-03-22 
10:58:31 UTC (rev 42093)
+++ trunk/mcs/class/System.Data/System.Data.Common/ChangeLog    2005-03-22 
10:58:48 UTC (rev 42094)
@@ -1,3 +1,12 @@
+2005-03-22  Sureshkumar T  <[EMAIL PROTECTED]>
+
+       * DbDataAdapter.cs: Update (): update the rows based on the
+       UpdateRowSource property. Process further based on the
+       RowUpdatedEvent handler argument's Status property.
+
+       Fixes bug #73587. Thanks to [EMAIL PROTECTED] (Ingo Bauersachs) for
+       bug report and patch.
+
 2005-03-01  Sureshkumar T  <[EMAIL PROTECTED]>
 
        * ConnectionStringsSectionHandler.cs: Added. configuration section

Modified: trunk/mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs
===================================================================
--- trunk/mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs     
2005-03-22 10:58:31 UTC (rev 42093)
+++ trunk/mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs     
2005-03-22 10:58:48 UTC (rev 42094)
@@ -719,14 +719,14 @@
                                if (command == null)
                                        useCommandBuilder = true;
 
-                               RowUpdatingEventArgs args = 
CreateRowUpdatingEvent (row, command, statementType, tableMapping);
-                               OnRowUpdating (args);
+                               RowUpdatingEventArgs updatingArgs = 
CreateRowUpdatingEvent (row, command, statementType, tableMapping);
+                               OnRowUpdating (updatingArgs);
 
-                               if (args.Status == UpdateStatus.ErrorsOccurred)
-                                       throw (args.Errors);
+                               if (updatingArgs.Status == 
UpdateStatus.ErrorsOccurred)
+                                       throw (updatingArgs.Errors);
 
-                               if (command == null && args.Command != null)
-                                       command = args.Command;
+                               if (command == null && updatingArgs.Command != 
null)
+                                       command = updatingArgs.Command;
                                else if (command == null)
                                        throw new InvalidOperationException 
(String.Format ("Update requires a valid {0}Command when passed a DataRow 
collection with modified rows.", commandName));
 
@@ -766,18 +766,22 @@
                                         // update the current row, if the 
update command returns any resultset
                                         // ignore other than the first record.
                                         DataColumnMappingCollection 
columnMappings = tableMapping.ColumnMappings;
-                                        if (reader.Read ()){
-                                                DataTable retSchema = 
reader.GetSchemaTable ();
-                                                foreach (DataRow dr in 
retSchema.Rows) {
-                                                        string columnName = dr 
["ColumnName"].ToString ();
-                                                        string dstColumnName = 
columnName;
-                                                        if (columnMappings != 
null &&
-                                                            
columnMappings.Contains(columnName))
-                                                                dstColumnName 
= columnMappings [dstColumnName].DataSetColumn;
-                                                        try {
-                                                                row 
[dstColumnName] = reader [columnName];
-                                                        }catch (Exception) {} 
// column is not available here
+
+                                        if (command.UpdatedRowSource == 
UpdateRowSource.Both ||
+                                            command.UpdatedRowSource == 
UpdateRowSource.FirstReturnedRecord) {
+                                                if (reader.Read ()){
+                                                        DataTable retSchema = 
reader.GetSchemaTable ();
+                                                        foreach (DataRow dr in 
retSchema.Rows) {
+                                                                string 
columnName = dr ["ColumnName"].ToString ();
+                                                                string 
dstColumnName = columnName;
+                                                                if 
(columnMappings != null &&
+                                                                    
columnMappings.Contains(columnName))
+                                                                        
dstColumnName = columnMappings [dstColumnName].DataSetColumn;
+                                                                try {
+                                                                        row 
[dstColumnName] = reader [columnName];
+                                                                }catch 
(Exception) {} // column is not available here
                                                         
+                                                        }
                                                 }
                                         }
 
@@ -790,22 +794,39 @@
                                                                                
  commandName +"Command affected 0 records.");
                                        updateCount += tmp;
                                         
-                                        // Update output parameters to row 
values
-                                        foreach (IDataParameter parameter in 
command.Parameters) {
+                                        if (command.UpdatedRowSource == 
UpdateRowSource.Both ||
+                                            command.UpdatedRowSource == 
UpdateRowSource.OutputParameters) {
+                                                // Update output parameters to 
row values
+                                                foreach (IDataParameter 
parameter in command.Parameters) {
 
-                                                if (parameter.Direction != 
ParameterDirection.InputOutput
-                                                    && parameter.Direction != 
ParameterDirection.Output
-                                                    && parameter.Direction != 
ParameterDirection.ReturnValue)
-                                                        continue;
+                                                        if 
(parameter.Direction != ParameterDirection.InputOutput
+                                                            && 
parameter.Direction != ParameterDirection.Output
+                                                            && 
parameter.Direction != ParameterDirection.ReturnValue)
+                                                                continue;
 
-                                                string dsColumnName = 
parameter.SourceColumn;
-                                                if (columnMappings != null &&
-                                                    
columnMappings.Contains(parameter.SourceColumn))
-                                                        dsColumnName = 
columnMappings [parameter.SourceColumn].DataSetColumn;
-                                                row [dsColumnName] = 
parameter.Value;
+                                                        string dsColumnName = 
parameter.SourceColumn;
+                                                        if (columnMappings != 
null &&
+                                                            
columnMappings.Contains(parameter.SourceColumn))
+                                                                dsColumnName = 
columnMappings [parameter.SourceColumn].DataSetColumn;
+                                                        row [dsColumnName] = 
parameter.Value;
+                                                }
                                         }
+                                        
 
-                                       OnRowUpdated (CreateRowUpdatedEvent 
(row, command, statementType, tableMapping));
+                                        RowUpdatedEventArgs updatedArgs = 
CreateRowUpdatedEvent(row, command, statementType, tableMapping);
+                                        OnRowUpdated(updatedArgs);
+                                        switch(updatedArgs.Status) {
+                                        case UpdateStatus.Continue:
+                                                row.AcceptChanges();
+                                                break;
+                                        case UpdateStatus.ErrorsOccurred:
+                                                throw(updatedArgs.Errors);
+                                        case UpdateStatus.SkipCurrentRow:
+                                                continue;
+                                        case UpdateStatus.SkipAllRemainingRows:
+                                                row.AcceptChanges ();
+                                                return updateCount;
+                                        }
                                        row.AcceptChanges ();
                                }
                                catch (Exception e)

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to