By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,480 Members | 763 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,480 IT Pros & Developers. It's quick & easy.

Comparing Dataset Question

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a
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.