Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / October 2007

Tip: Looking for answers? Try searching our database.

Comparing Dataset Question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Franck - 19 Oct 2007 14:36 GMT
how come unchanged always true even if data changed

This code come from my saving button:

============================================
DataSet ds1 = new DataSet();
DataSet ds2 = new DataSet();
DataSet ds3 = new DataSet();

//Static Dataset which contain values when my form load
ds1.Tables.Add(ModelSelectionGlobal.dsModelSelection.Tables["C"].Copy());
//this datatable contain the value of all controls when saving
ds2.Tables.Add(dt.Copy());

ds3.Merge(ds1);
ds3.AcceptChanges();
//now ds1 supposed to be the reference
ds3.Merge(ds2);
//ds2 contain the same structure as ds1 but may have different values

//this test should tell me is ds2 changed ds1 but it does always
return true
if (ds3.HasChanges(DataRowState.Unchanged) == false)
{
     for (int y = 0; y <= 31; y++)
     {
           //filling data with datarows of dt
           ModelSelectionGlobal.dsModelSelection.Tables["C"].Rows[0]
[y] = dr[y];
     }
}
=======================================================

what im doing wrong here ?
Adam Bieganski - 19 Oct 2007 15:21 GMT
Hi Franck,

> if (ds3.HasChanges(DataRowState.Unchanged) == false)

I think instead you should try:
if (ds3.HasChanges() == false)

and you can actually skip the comparing to 'false':
if (!ds3.HasChanges())

Hope this helps :)
Signature

_____________
Adam Bieganski
http://godevelop.blogspot.com

> how come unchanged always true even if data changed
>
[quoted text clipped - 30 lines]
>
> what im doing wrong here ?
Franck - 19 Oct 2007 17:01 GMT
> Hi Franck,
>
[quoted text clipped - 45 lines]
>
> > what im doing wrong here ?

This works but i have a second issue.
when i merge ds2 inside ds3 i thought it would overwrite ds1 thats
already there but it's not. even if the tables have the same name it
does not replace but create another table, so in my ds3 the ds1 is :
ds3.table[0] and ds2 is ds3.table[1]. that's why haschanges say it
havent been changed.
Adam Bieganski - 19 Oct 2007 17:21 GMT
> > Hi Franck,
> >
[quoted text clipped - 52 lines]
> ds3.table[0] and ds2 is ds3.table[1]. that's why haschanges say it
> havent been changed.

I think you can get rid of the first 2 datasets completely:

ds3.Tables.Add(ModelSelectionGlobal.dsModelSelection.Tables["C"].Copy());
ds3.AcceptChanges();
ds3.Merge(dt.Copy());

If this doesn't help - try to explicitly set the names of the tables
returned by the Copy() methods:

DataTable dt1 = ModelSelectionGlobal.dsModelSelection.Tables["C"].Copy();
dt1.TableName = "Table1";
ds3.Tables.Add(dt1);
ds3.AcceptChanges();
dt1 = dt.Copy();
dt1.TableName = "Table1";
ds3.Merge(dt1);

Cheers,
Signature

_____________
Adam Bieganski
http://godevelop.blogspot.com

Franck - 19 Oct 2007 19:31 GMT
> > > Hi Franck,
>
[quoted text clipped - 74 lines]
> _____________
> Adam Bieganskihttp://godevelop.blogspot.com

nothing works,

gonna do if statement with and compare all my fields one by one this
im sure it works.
Cor Ligthert[MVP] - 20 Oct 2007 10:49 GMT
Frank,

AFAIK does merge not change the rowstates, the merge is merging rows (and
adding and changing new ones for old ones, however is not affecting the
fields).

Cor

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.