DataView does not show existing records after calling DataSet.Merge (ADO.NET 1.1 Bug?)

O

Oleg

Hi,

I have a problem when DataView does not show any data
though it really contains it. It happens after merging a dataset into
another dataset.
The code example is very simple. First message box shows zero and second
shows 1.
In order to see new record you have to re-initilize the DataView.
I've found that if I don't call BeginLoadData/EndLoadData before merging
everything works correct. But I really need to call these methods
because otherwise DataView's ListChanged event
will be fired by Merge method
and my application requires that such an event should not occur.

//first dataset
DataSet testDS1 = new DataSet();
DataTable dt = new DataTable("Table1");
testDS1.Tables.Add(dt);
dt.Columns.Add("Col1", typeof(int));
dt.PrimaryKey = new DataColumn[] {dt.Columns[0]};
//another dataset
DataSet ds = testDS1.Clone();
//dataview
DataView dv = new DataView(ds.Tables[0]);
//load test data
testDS1.Tables[0].BeginLoadData();
testDS1.Tables[0].LoadDataRow(new object[] {1}, true);
testDS1.Tables[0].EndLoadData();
//merging
ds.Tables[0].BeginLoadData();
ds.Merge(testDS1);
ds.AcceptChanges();
ds.Tables[0].EndLoadData();
MessageBox.Show(dv.Count.ToString());
dv.BeginInit();
dv.EndInit();
MessageBox.Show(dv.Count.ToString());

Does anyone know what is the reason and how to avoid such a problem?

Thank you,

Oleg
 
C

Cor Ligthert

Oleg,

I don't know what I do wrong however with your code I get 2 times 1.

Cor
 

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