HasChanges() and GetChanges() ?

G

Guest

good morning.
I'm writing from Italy, and I have this question:

if i have a dataset, i write:

ds.Tables[0].Rows.Remove(ds.Tables[0].Rows[0]);

ds.AcceptChanges();

why HasChanges() is false and GetChanges() doesn't return anything?

thanks
Good Bye


Francesco Sangiuseppe.
 
M

Miha Markic [MVP C#]

Hi Francesco,

Francesco Sangiuseppe said:
good morning.
I'm writing from Italy, and I have this question:

Italy is nice :)
if i have a dataset, i write:

ds.Tables[0].Rows.Remove(ds.Tables[0].Rows[0]);

ds.AcceptChanges();

why HasChanges() is false and GetChanges() doesn't return anything?

Becuase one row above you invoked AcceptChanges.
 
C

Cor Ligthert

I'm writing from Italy, and I have this question:
Italy is nice :)
And so near Slovenia could you not go visit Francesco?

Because of the accepting the change that they both now are EU you have not
even to declare anything at the doane anymore because the difference
disapeared while when that acceptchange had not been done is was something
that had to be done.

Could not find a more realistic sample accoording to that acceptchange
accoording to Italy and Slovenia

:)

Cor
 
M

Miha Markic [MVP C#]

Cor Ligthert said:
And so near Slovenia could you not go visit Francesco?

Because of the accepting the change that they both now are EU you have not
even to declare anything at the doane anymore because the difference
disapeared while when that acceptchange had not been done is was something
that had to be done.

Could not find a more realistic sample accoording to that acceptchange
accoording to Italy and Slovenia

LOL, the police is still at the border though.
Watch out, I might come to Netherland one day :)
 
W

William Ryan eMVP

Like Miha mentions you are calling .AcceptChanges which will definitely
cause GetChanges to have nothing to return.
http://www.knowdotnet.com/articles/efficient_pt4.html However in this case
you have an additional problem in that you are calling .Remove instead of
..Delete. If you call .Delete, you aren't getting rid of anything until you
call Acceptchanges on it - you are simply changing the rowstate. If you
call Remove, it's gone from the collection.
DataRow dro = ds.Tables[0].Rows[0];

ds.Tables[0].Rows.Remove(dro);

MessageBox.Show(ds.HasChanges().ToString());//False

If you read that same article reference above, I go through an example of
the difference. In this case I think Remove it's what's technically causing
the problem, but if you change it to .Delete, it still won't work b/c of the
AcceptChanges. So change the Remove to Delete and then take out the line on
AcceptChanges
--

W.G. Ryan, eMVP

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/community/newsgroups
 
C

Cor Ligthert

ds.Tables[0].Rows.Remove(dro);
I was checking and checking to make a message because that Italia and
Slovenia and than I missed this (Miha as well so it is not that bad)

brrrrrrrrrrrrrrrrr

Good one Bill.

:)

Cor
 
M

Miha Markic [MVP C#]

It seems that I've developed an "interrupt" when I see AcceptChanges in
situation like this :)

Miha

Cor Ligthert said:
ds.Tables[0].Rows.Remove(dro);
I was checking and checking to make a message because that Italia and
Slovenia and than I missed this (Miha as well so it is not that bad)

brrrrrrrrrrrrrrrrr

Good one Bill.

:)

Cor
 
W

William Ryan eMVP

Me too. I had a really bad incident with Remove vs. Delete when I was first
learning ADO.NET - Really bad so whenever I see it the little light goes
off and says "probably not what they want to use" And I'll take my first
experiences with client side transactions to the grave with me - but i had a
few disasters with those too ;-)

--

W.G. Ryan, eMVP

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/community/newsgroups
Miha Markic said:
It seems that I've developed an "interrupt" when I see AcceptChanges in
situation like this :)

Miha

Cor Ligthert said:
ds.Tables[0].Rows.Remove(dro);
I was checking and checking to make a message because that Italia and
Slovenia and than I missed this (Miha as well so it is not that bad)

brrrrrrrrrrrrrrrrr

Good one Bill.

:)

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