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
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