Nasty DataView bug

B

Bob L.

Hi, everyone,

I ran into a serious bug upgrading to VS2005, and very easy to reproduce. It
goes like this:

1. Filter a DataView
2. Get a reference to a DataRowView
3. Clear the filter - the reference to the DataRowView has changed to a
completely different row!

This is not a problem in .NET 1.1 - only in 2.0. The code to reproduce the
problem is below. Please help!

Thanks,
Bob L.


Dim oTable As DataTable
Dim oView As DataView
Dim oRowView As DataRowView

'Build simple table
oTable = New DataTable
oTable.Columns.Add("ID", GetType(Integer))
oTable.Rows.Add(New Object() {12})
oTable.Rows.Add(New Object() {25})

'Construct & filter DataView
oView = New DataView(oTable)
oView.RowFilter = "ID=25"

'Get a reference to the found item and display the ID
oRowView = oView.Item(0)
MsgBox(oRowView.Item(0)) 'ID = 25

oView.RowFilter = ""

'Show the same ID again
'In 1.1 this line of code still shows 25 - correct.
'In 2.0 it shows 12 - wrong!
MsgBox(oRowView.Item(0))
 
B

Bob L.

I appreciate the response, but that's a tough sell. The row is valid with or
without the filter, so it should remain the same. Obviously the object is
being reloaded with whatever is the first element in the list, but it is
atypical to mess around with an existing object behind the scenes.

The bottom line is that it breaks our application and we need a fix or
workaround. So to say this was "fixed" in 2.0 doesn't get us to our goal!

- Bob
 
S

Sahil Malik [MVP]

Well .. truthfully I'm not trying to sell :) .. I don't represent MS

... but anyway .. lets consider a simile, when you are working with a
database table, do you rely on default indexing or do you sort and then are
assured of the indexing? I'm guessing it's the latter - so why should
dataviews be any different?

Either way I have raised it to internal MS folks .. maybe they will have a
better answer.

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
 
D

David Sceppa [MSFT]

Thanks for bringing this to our attention, Bob. I'm working with
people to investigate the issue.

In the future, please submit bug reports such as these to the product
feedback site http://lab.msdn.microsoft.com/productfeedback/ That's not to
say you can't discuss issues like these on the newsgroups. The MSDN
Product Feedback site just makes it easier for us to track issues such as
these.

David Sceppa
Microsoft
This posting is provided "AS IS" with no warranties,
and confers no rights. You assume all risk for your use.
© 2005 Microsoft Corporation. All rights reserved.
 
S

Simon

Hi Bob,

As frustrating as it is, I think I have to agree with Sahil. Take the
example.

select * from sometable where somefiled = 'fred'

Now get the first row of the result set

Now remove the where clause and the chances are you will get a different
row.

Isn't this sort of synonymous.

In other words I think the behaviour in 2.0 is more intuitive. I would
have expected to have grabbed the value from the filtered dataview and
done something with it before removing the filter.

Just my 2c,

Cheers

Simon
 
B

Bob L.

Simon,

I agree that it is more intuitive from a database standpoint, but I think
less intuitive from an object standpoint. Either way, Microsoft changed the
way this worked when they were supposed to be maintaining backwards
compatibility, but worse, doesn't appear to have documented this change
anywhere. We can't plan ahead for what we are not told about!

- Bob
 
S

Sahil Malik [MVP C#]

Okay but .NET 1.1 documentation says changing the filter will change the
rows .. so even in 1.1, when you changed the RowFilter, why should you
expect the rows to stay the same? ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top