467,151 Members | 1,102 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,151 developers. It's quick & easy.

Comparing Dataset Question

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.dsModelSelecti on.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 ?

Oct 19 '07 #1
  • viewed: 1604
Share:
5 Replies
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" wrote:
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.dsModelSelecti on.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 ?

Oct 19 '07 #2
On Oct 19, 10:21 am, Adam Bieganski <abieganski(at)gmail.comwrote:
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" wrote:
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.dsModelSelecti on.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.

Oct 19 '07 #3
"Franck" wrote:
On Oct 19, 10:21 am, Adam Bieganski <abieganski(at)gmail.comwrote:
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" wrote:
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.dsModelSelecti on.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.dsModelSelecti on.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,
--
_____________
Adam Bieganski
http://godevelop.blogspot.com

Oct 19 '07 #4
On Oct 19, 12:21 pm, Adam Bieganski <abieganski(at)gmail.comwrote:
"Franck" wrote:
On Oct 19, 10:21 am, Adam Bieganski <abieganski(at)gmail.comwrote:
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" wrote:
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.dsModelSelecti on.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.dsModelSelecti on.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,
--
_____________
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.

Oct 19 '07 #5
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

Oct 20 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Eric | last post: by
3 posts views Thread by JamesWilce | last post: by
reply views Thread by Elliot M. Rodriguez | last post: by
19 posts views Thread by Will Lastname | last post: by
11 posts views Thread by Jeff | last post: by
22 posts views Thread by Arne | last post: by
4 posts views Thread by Frank | last post: by
5 posts views Thread by Frank | last post: by
2 posts views Thread by Nick Hodge \(MVP\) | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.