Index: System.Data.Common/DbDataAdapter.cs
===================================================================
RCS file: /mono/mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs,v
retrieving revision 1.22
diff -u -r1.22 DbDataAdapter.cs
--- System.Data.Common/DbDataAdapter.cs	24 Feb 2003 17:47:28 -0000	1.22
+++ System.Data.Common/DbDataAdapter.cs	25 Feb 2003 07:04:22 -0000
@@ -97,7 +102,6 @@
 			return Fill (dataSet, 0, 0, srcTable, SelectCommand, CommandBehavior.Default);
 		}
 
-		[MonoTODO ("Support filling after we have already filled.")]
 		protected virtual int Fill (DataTable dataTable, IDataReader dataReader) 
 		{
 			int count = 0;
@@ -136,7 +140,6 @@
 			return this.Fill (dataSet, startRecord, maxRecords, srcTable, SelectCommand, CommandBehavior.Default);
 		}
 
-		[MonoTODO ("Support filling after we have already filled.")]
 		protected virtual int Fill (DataSet dataSet, string srcTable, IDataReader dataReader, int startRecord, int maxRecords) 
 		{
 			if (startRecord < 0)
@@ -291,30 +294,31 @@
 		[MonoTODO ("Test")]
 		private void BuildSchema (IDataReader reader, DataTable table, SchemaType schemaType)
 		{
-			string sourceColumnName;
-			string sourceTableName;
-			string dsColumnName;
-
-			ArrayList primaryKey = new ArrayList (); 	
-			table.Columns.Clear ();
+			ArrayList primaryKey = new ArrayList ();
+			ArrayList sourceColumns = new ArrayList ();
 
 			foreach (DataRow schemaRow in reader.GetSchemaTable ().Rows) {
-				// generate a unique column name in the dataset table.
+				string sourceTableName;
+				if (schemaRow ["BaseTableName"].Equals (DBNull.Value))
+					sourceTableName = table.TableName; 
+				else
+					sourceTableName = (string) schemaRow ["BaseTableName"];
+
+				// generate a unique column name in the source table.
+				string sourceColumnName;
 				if (schemaRow ["BaseColumnName"].Equals (DBNull.Value))
 					sourceColumnName = DefaultSourceColumnName;
 				else 
 					sourceColumnName = (string) schemaRow ["BaseColumnName"];
 
-				dsColumnName = sourceColumnName;
+				string realSourceColumnName = sourceColumnName;
 
-				for (int i = 1; table.Columns.Contains (dsColumnName); i += 1) 
-					dsColumnName = String.Format ("{0}{1}", sourceColumnName, i);
-
-				if (schemaRow ["BaseTableName"].Equals (DBNull.Value))
-					sourceTableName = table.TableName; 
-				else
-					sourceTableName = (string) schemaRow ["BaseTableName"];
+				for (int i = 1; sourceColumns.Contains (realSourceColumnName); i += 1) 
+					realSourceColumnName = String.Format ("{0}{1}", sourceColumnName, i);
+				sourceColumns.Add(realSourceColumnName);
 
+				// generate DataSetColumnName from DataTableMapping, if any
+				string dsColumnName = realSourceColumnName;
 				DataTableMapping tableMapping = null;
 				if (schemaType == SchemaType.Mapped)
 					tableMapping = DataTableMappingCollection.GetTableMappingBySchemaAction (TableMappings, sourceTableName, table.TableName, MissingMappingAction.Ignore); 
@@ -331,8 +335,8 @@
 						TableMappings.Add (tableMapping);
 				}
 
-				table.Columns.Add (dsColumnName, (Type) schemaRow ["DataType"]);
-
+				if (!table.Columns.Contains(dsColumnName))
+					table.Columns.Add (dsColumnName, (Type) schemaRow ["DataType"]);
 
 				if (!schemaRow["IsKey"].Equals (DBNull.Value))
 					if ((bool) (schemaRow ["IsKey"]))
@@ -427,7 +431,9 @@
 					DataColumnMappingCollection columnMappings = tableMapping.ColumnMappings;
 
 					foreach (IDataParameter parameter in command.Parameters) {
-						string dsColumnName = columnMappings [parameter.SourceColumn].DataSetColumn;
+						string dsColumnName = parameter.SourceColumn;
+						DataColumnMapping mapping = columnMappings [parameter.SourceColumn];
+						if (mapping != null) dsColumnName = mapping.DataSetColumn;
 						DataRowVersion rowVersion = DataRowVersion.Proposed;
 
 						// Parameter version is ignored for non-update commands
