PC Review


Reply
Thread Tools Rate Thread

DataSet with multiple tables - which one has changes?

 
 
PeterZ
Guest
Posts: n/a
 
      20th May 2004
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


 
Reply With Quote
 
 
 
 
Fred
Guest
Posts: n/a
 
      20th May 2004
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" <_(E-Mail Removed)> wrote in message
news:40abffd0$0$3037$(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
DNE
Guest
Posts: n/a
 
      20th May 2004
Also

DataTable.GetChanges method

--

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


"Fred" <(E-Mail Removed)> wrote in message
news:#(E-Mail Removed)...
> 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" <_(E-Mail Removed)> wrote in message
> news:40abffd0$0$3037$(E-Mail Removed)...
> > 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
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dataset with multiple tables Andrea Microsoft ASP .NET 1 18th Oct 2008 07:16 PM
DataSet Designer/adding multiple tables to a dataset/ how? =?Utf-8?B?Q3VydGlz?= Microsoft ADO .NET 1 21st Aug 2006 03:09 PM
multiple tables within a dataset Craig G Microsoft VB .NET 4 8th Dec 2004 04:33 PM
Multiple tables in a dataset Raj Microsoft Dot NET Compact Framework 0 10th Dec 2003 11:31 PM
Multiple tables in dataset Juan Romero Microsoft ADO .NET 3 9th Sep 2003 08:19 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:06 PM.