G
Guest
We converted our app from 1.1 to 2 and some code was no longer working.
The case: From a non typed datatable, convert it to a typed one.
How to reproduce the bug:
-------------------------------
1) Create a project.
2) Add a new Dataset (keep DataSet1).
a) Add a new DataTable (Keep DataTable1)
b) Add a new DataColumn (Keep DataColumn1)
3) Add a new Window form.
4) Add a button.
5) Add button click event and add the following code:
***** Code : Start *****
// We defined a non-typed DataTable in a Dataset.
DataSet mDataset = new DataSet();
DataTable mDataTable = mDataset.Tables.Add("DataTable1");
DataColumn mDataColumn = mDataTable.Columns.Add("Column1");
mDataColumn.DataType = typeof(string);
// Adding a row in the non-typed DataTable.
mDataset.Tables[0].Rows.Add(new object[] { "A" });
// Temporary Typed Dataset to transfer.
DataSet1 mTmpds = new DataSet1();
mTmpds.Merge(mDataset.Tables[0], false, MissingSchemaAction.Ignore);
// Removing the non-typed and merging the Typed.
mDataset.Tables.RemoveAt(0);
mDataset.Merge(mTmpds);
// Trying to access Column1 and show the value.
Console.WriteLine(((DataSet1.DataTable1DataTable)mDataset.Tables[0])[0].Column1);
***** Code : End *****
Note:
The problem seam to be the non transfer of the column table reference. Look
like to be linked to the old table. I checked the code and found that it is
because the column property "Table" is not the same has the table object.
MS Code: DataRow - private void CheckColumn(DataColumn column)
-----------
....
if (column.Table != this._table)
{
throw ExceptionBuilder.ColumnNotInTheTable(column.ColumnName,
this._table.TableName);
}
That was working in DotNet 1.1.
The case: From a non typed datatable, convert it to a typed one.
How to reproduce the bug:
-------------------------------
1) Create a project.
2) Add a new Dataset (keep DataSet1).
a) Add a new DataTable (Keep DataTable1)
b) Add a new DataColumn (Keep DataColumn1)
3) Add a new Window form.
4) Add a button.
5) Add button click event and add the following code:
***** Code : Start *****
// We defined a non-typed DataTable in a Dataset.
DataSet mDataset = new DataSet();
DataTable mDataTable = mDataset.Tables.Add("DataTable1");
DataColumn mDataColumn = mDataTable.Columns.Add("Column1");
mDataColumn.DataType = typeof(string);
// Adding a row in the non-typed DataTable.
mDataset.Tables[0].Rows.Add(new object[] { "A" });
// Temporary Typed Dataset to transfer.
DataSet1 mTmpds = new DataSet1();
mTmpds.Merge(mDataset.Tables[0], false, MissingSchemaAction.Ignore);
// Removing the non-typed and merging the Typed.
mDataset.Tables.RemoveAt(0);
mDataset.Merge(mTmpds);
// Trying to access Column1 and show the value.
Console.WriteLine(((DataSet1.DataTable1DataTable)mDataset.Tables[0])[0].Column1);
***** Code : End *****
Note:
The problem seam to be the non transfer of the column table reference. Look
like to be linked to the old table. I checked the code and found that it is
because the column property "Table" is not the same has the table object.
MS Code: DataRow - private void CheckColumn(DataColumn column)
-----------
....
if (column.Table != this._table)
{
throw ExceptionBuilder.ColumnNotInTheTable(column.ColumnName,
this._table.TableName);
}
That was working in DotNet 1.1.