After Merge of Typed Dataset access to row fields causes System.ArgumentException

I am using typed dataset(generated by VS 2005) that I merged to empty dataset (actually to class, derived from dataset).

When I am accessed a particular row and tried to read value of the row field, I've got 

System.ArgumentException: Column <ColumnName> does not belong to table <TableName>. at System.Data.DataRow.CheckColumn(DataColumn column)

After debugging and digging into Designer generated code, I found that the cause is that
the generated typed-safe columns have property Table as null, when it is exspected to be a reference to owner table.

The fix was unexpectedely easy.

For merged tables it is required to call InitVars() method of generated Table class.
The Table
InitVars() looks like the following
internal void InitVars() {
//For each  table column

this.columnRetrieved = base.Columns["Retrieved"];
}
The function InitVars()  is called in Table constructor and Clone, but is not called during Merge.
It as not a bug, but it should be considered when merge typed datasets into untyped one.

 

posted @ Friday, November 10, 2006 12:58 PM

Print

Comments on this entry:

# re: After Merge of Typed Dataset access to row fields causes System.ArgumentException

Left by Johirul Islam at 9/23/2008 4:33 AM
Gravatar
ds1.Merge(ds2); not working where bothe the dataset having same datasetname, tablename, columnname and rowvalue for each column.

Your comment:



 (will not be displayed)


 
 
 
 
 

Live Comment Preview:

 
«November»
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345