Comparing Dataset Question

F

Franck

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

Guest

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 :)
--
_____________
Adam Bieganski
http://godevelop.blogspot.com


Franck said:
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 ?
 
F

Franck

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 :)
--
_____________
Adam Bieganskihttp://godevelop.blogspot.com

Franck said:
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 ?

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

Guest

Franck said:
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 :)
--
_____________
Adam Bieganskihttp://godevelop.blogspot.com

Franck said:
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 ?

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.

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

Franck

Franck said:
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 :)
--
_____________
Adam Bieganskihttp://godevelop.blogspot.com
:
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 ?
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.

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,

nothing works,

gonna do if statement with and compare all my fields one by one this
im sure it works.
 
C

Cor Ligthert[MVP]

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
 

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