DataSet with multiple tables - which one has changes?

P

PeterZ

Hi,

I have win forms project, a single dataset named "dsAllTables" holding 4
tables. I have a seperate dataAdapter for each table named "daTable_#".

I know I can detect if the dataset as a whole has changes, but how do I
detect which specific table in the dataset has changes?


This is something I want to do, obviously it won't compile becase there's no
HasChanges() method on a table:
------------------------------------------------------------------

private void btnSave_Click(object sender, System.EventArgs e)
{
this.BindingContext[dsAllTables, "TABLE_1"].EndCurrentEdit();
this.BindingContext[dsAllTables, "TABLE_2"].EndCurrentEdit();
this.BindingContext[dsAllTables, "TABLE_3"].EndCurrentEdit();
this.BindingContext[dsAllTables, "TABLE_4"].EndCurrentEdit();

try
{
if (dsAllTables.Tables["TABLE_1"].HasChanges()) //<-- how do I achieve
this?
this.daTable_1.Update(this.dsAllTables.Tables["TABLE_1"]);
if (dsAllTables.Tables["TABLE_2"].HasChanges())
this.daTable_2.Update(this.dsAllTables.Tables["TABLE_2"]);
if (dsAllTables.Tables["TABLE_3"].HasChanges())
this.daTable_3.Update(this.dsAllTables.Tables["TABLE_3"]);
if (dsAllTables.Tables["TABLE_4"].HasChanges())
this.daTable_4.Update(this.dsAllTables.Tables["TABLE_4"]);

this.dsAllTables.AcceptChanges();
MessageBox.Show("All changes saved");
}
catch (OleDbException ex)
{
MessageBox.Show(ex.Message, "Saving changes failed.");
}
}

------------------------------------------------------------------

Appreciate any ideas!

Cheers,
PeterZ
 
F

Fred

Hi Peter,

You could create one BindingManagerBase for each table and hook up the
events CurrentChanged:

BindingManagerBase bm = BindingContext[MyDataSet, "Table1"];
bm.PositionChanged += new System.EventHandler(this.Table1PositionChanged);

bm.CurrentChanged += new System.EventHandler(this.Table1DataChanged);

Fred
 
D

DNE

Also

DataTable.GetChanges method

--

Ori Millo
Solutions Consultant
SEA Software Ever After
http://www.s-e-a.com.au


Fred said:
Hi Peter,

You could create one BindingManagerBase for each table and hook up the
events CurrentChanged:

BindingManagerBase bm = BindingContext[MyDataSet, "Table1"];
bm.PositionChanged += new System.EventHandler(this.Table1PositionChanged);

bm.CurrentChanged += new System.EventHandler(this.Table1DataChanged);

Fred

PeterZ said:
Hi,

I have win forms project, a single dataset named "dsAllTables" holding 4
tables. I have a seperate dataAdapter for each table named "daTable_#".

I know I can detect if the dataset as a whole has changes, but how do I
detect which specific table in the dataset has changes?


This is something I want to do, obviously it won't compile becase
there's
no
HasChanges() method on a table:
------------------------------------------------------------------

private void btnSave_Click(object sender, System.EventArgs e)
{
this.BindingContext[dsAllTables, "TABLE_1"].EndCurrentEdit();
this.BindingContext[dsAllTables, "TABLE_2"].EndCurrentEdit();
this.BindingContext[dsAllTables, "TABLE_3"].EndCurrentEdit();
this.BindingContext[dsAllTables, "TABLE_4"].EndCurrentEdit();

try
{
if (dsAllTables.Tables["TABLE_1"].HasChanges()) file://<-- how do I achieve
this?
this.daTable_1.Update(this.dsAllTables.Tables["TABLE_1"]);
if (dsAllTables.Tables["TABLE_2"].HasChanges())
this.daTable_2.Update(this.dsAllTables.Tables["TABLE_2"]);
if (dsAllTables.Tables["TABLE_3"].HasChanges())
this.daTable_3.Update(this.dsAllTables.Tables["TABLE_3"]);
if (dsAllTables.Tables["TABLE_4"].HasChanges())
this.daTable_4.Update(this.dsAllTables.Tables["TABLE_4"]);

this.dsAllTables.AcceptChanges();
MessageBox.Show("All changes saved");
}
catch (OleDbException ex)
{
MessageBox.Show(ex.Message, "Saving changes failed.");
}
}

------------------------------------------------------------------

Appreciate any ideas!

Cheers,
PeterZ
 

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