Bug #7569 DataColumnMapping
Submitted: 29 Dec 2004 9:44 Modified: 11 Oct 2005 7:49
Reporter: Test Test Email Updates:
Status: Can't repeat Impact on me:
None 
Category:Connector / NET Severity:S1 (Critical)
Version:1.03 OS:Windows (Windows XP - SP2)
Assigned to: Reggie Burnett CPU Architecture:Any

[29 Dec 2004 9:44] Test Test
Description:
I use a DataColumnMapping in the MySql.Data.DataAdapter and fill a DataTable. Then i bind the DataTable to a DataGrid and see that the ColumnMappings are done right (example: ID => Identifier, dcname => Name; you can see it at the ColumnCaptions in the Grid).

Now i change some values in the Grid and update the DataTable with a MySQL.Data.DataAdapter using a MySQL.Data.CommandBuilder.

When calling the DataAdapter.Update(DataTable) Method an error occures.

ErrorMessage: The Column dcname is not in the ...Table.

The same code (with SQLAdapter, and CommandBuilder) with an identic table in SQL Server 2000, runs perfectly.

How to repeat:
Create a table with the columns ID (Primary int), dcname (varchar) => add some rows.

Use a DataAdapter to fill a DataTable and before calling the fill-Method set some 

After that bind the DataTable to a DataGrid make some changes in the Values and Update the DataTable with a DataAdapter and a CommandBuilder on it:

Add the same ColumnMappings to the Adapter.
Call Adapter.Update(table);
[5 Jan 2005 17:43] Reggie Burnett
Can you post some source code that shows this problem?  Thanks
[8 Mar 2005 18:24] Will Britton
I am also experiencing this problem.
Code:

			// Create dataset and add table, columns, data
			DataSet objDataset = new DataSet();

			objDataset.Tables.Add("DS_Manufacturer");
			objDataset.Tables["DS_Manufacturer"].Columns.Add("Id",typeof(System.Int32));
			objDataset.Tables["DS_Manufacturer"].Columns.Add("Name",typeof(System.String));
			objDataset.Tables["DS_Manufacturer"].Columns.Add("OwnerId",typeof(System.Int32));
			objDataset.Tables["DS_Manufacturer"].Columns.Add("UpdateSequence",typeof(System.Int32));

			DataRow objRow = objDataset.Tables["DS_Manufacturer"].NewRow();

			objRow["Id"] = 123123;
			objRow["Name"] = "Test-name";
			objRow["OwnerId"] = 100;
			objRow["UpdateSequence"] = 123456;

			// Create a data adapter
			MySqlDataAdapter objAdapter = new MySqlDataAdapter();

			// Create table and column mappings
			DataTableMapping objMapping = objAdapter.TableMappings.Add("Table","DS_Manufacturer");
			objMapping.ColumnMappings.Add("_organisationid","OwnerId");
			objMapping.ColumnMappings.Add("_UpdateSequence","UpdateSequence");

			// Set the select command
			objAdapter.SelectCommand = new MySqlCommand("SELECT * FROM manufacturer;",objDatabase);

			// Use command builder to create other commands
			MySqlCommandBuilder objBuilder = new MySqlCommandBuilder(objAdapter);

			// Load the original data from the database
			objAdapter.Fill(objDataset);

			// Modify the data
			objDataset.Tables["DS_Manufacturer"].Rows[0]["Name"] = "New-test-name";

			// Save the data to the database
			objAdapter.Update(objDataset);

Stepping through, the Fill command populates the dataset properly, however the Update command raises

System.ArgumentException : Column '_organisationid' does not belong to table DS_Manufacturer
[8 Mar 2005 19:44] Will Britton
Suggestion for bug-fix:

I tried the following, which worked, although I'm sure there must be a neater solution.

In MySqlClient/CommandBuilder.cs changed the SetParamterValues private function to...

private void SetParameterValues(MySqlCommand cmd, DataRow dataRow)
{
	foreach (MySqlParameter p in cmd.Parameters)
	{
		String strMappedTableName;
		String strDatasetTable = dataRow.Table.TableName;
		System.Data.Common.DataTableMapping objMapping = _adapter.TableMappings.GetByDataSetTable(strDatasetTable);

		strMappedTableName = 
			( objMapping != null && objMapping.ColumnMappings.Contains(p.SourceColumn))
			? objMapping.ColumnMappings[p.SourceColumn].DataSetColumn
			: p.SourceColumn;

		if (p.SourceVersion == DataRowVersion.Original)
			//				if (p.ParameterName.Length >= 8 && p.ParameterName.Substring(0, 8).Equals("Original"))
			p.Value = dataRow[ strMappedTableName, DataRowVersion.Original ];
		else
			p.Value = dataRow[ strMappedTableName, DataRowVersion.Current ];
	}
}
[11 Oct 2005 7:49] Vasily Kishkin
I was not able to reproduce the bug on 1.0.6. Probably the bug was fixed.