Re: Merging 2 datasets raises System.IndexOutOfRange exception

From: Steven (Steven_at_discussions.microsoft.com)
Date: 11/25/04


Date: Thu, 25 Nov 2004 09:49:09 -0800

Hi Val,

Sample code would be quite difficult, without posting a whole functioning
application, but I'll try to explain it a bit more in depth:

Let's say I have a business entity dataset called "Issue" (like in a
Bugtracking issue), which relates to a Issue table. This table has a couple
of relations to other tables (Foreign keys), one of the related fields is
StatusID. This points to a Status table, which contains Status values (Open,
Closed, etc.).

I want to show Issue rows in a Datagrid.
For that, I don't want to show the StatusID in the datagrid row, but the
Status value (Open, Closed, etc.). To accomplish this, I add expression
columns to my business entity dataset. The expression column (called
StatusValue) has a value of "Parent(IssueStatus).StatusValue". The result is
that I can select the StatusValue column to show up in my datagrid just like
any other column of the Issue table. The only difference is that it fetches
the data from a related table (and that it's readonly).

To fill the business entity dataset, I merge data from my datalayer in a
separate dataset. This separate dataset DOES NOT contain the expression
columns.
Because of another bug somewhere in ADO.NET (related to expression columns)
I've chosen to remove all expression columns in my business entity dataset
BEFORE merging the data from the datalayer dataset with the business layer
dataset. So, to stay with the above example, I remove the StatusValue column
from the Issue table.

Let's say that the Issue table has 4 "normal" columns, and 1 "expression"
column (the StatusValue column).

On the second merge (the first one seems to go oke all the time), I get an
exception that seems to state that the expression columns are still there. A
column count on both tables doesn't show that!!! The exception in the above
example would be "Cannot find column 5". Which is correct, since there are
only 4 columns left, in both the Issue table in the business entity dataset
and the Issue table in the data access layer dataset.

So, somehow, the Merge method still "sees" the expression columns, while
inspecting the Issue table doesn't show them. This seems like really sneaky
stuff to me. Where does the Merge method get it's column info from then,
since I can't see the extra columns through the Quick Watch window?

I've tried all the "MissingSchemaAction" options (Add, AddWithKey, etc.),
but none of those help. This stuff really puzzles me.

I hope this explaination helps a bit.

Bye,

Steven

"Val Mazur" wrote:

> Hi Steven,
>
> To see if it is a bug, I believe you would need to post some code, which
> would reproduce this issue
>
> --
> Val Mazur
> Microsoft MVP
>
>
> "Steven" <Steven@discussions.microsoft.com> wrote in message
> news:C3771A13-3F69-4BD8-B5A2-30FB8D230F6F@microsoft.com...
> >I have 2 datasets, a Business Entity dataset (where I add a couple of
> > expression columns to fetch data from Parent tables) and a Data Access
> > Layer
> > dataset (without the expression columns). First initial load of my
> > Business
> > Entity dataset works fine. Then, when I try to fetch new data, I get a
> > System.IndexOutOfRange exception with the message "Cannot find column 16".
> > When I check the offending table in both datasets, they both have 13
> > columns.
> >
> > Important note: Before I try to merge the latest DataAccessLayer dataset
> > into my BusinessEntity dataset, I clear my BusinessEntity dataset, and
> > remove
> > the Expression columns. After merging the two datasets, I add the
> > Expression
> > columns again.
> >
> > What's going on here? This really seems like a bug in the Merge
> > functionality of ADO.NET. It seems that the Merge still thinks that the
> > expression columns are there, which explains the reference to "Cannot find
> > column 16". How come?
>
>
>