Data Set Changes and Image importing

R

Radi Radichev

Hi!
I'm trying to check in the OnFormClosing event if the dataset has changes
that are still not commited and if yes to display a dialog box showing a
question if the user wants to save tha changes or not. I test it with
dataset.HasChanges() but it returns true even only when i change the record
with binding navigator... Does anybody know how to do this right?? Also how
can i load a picture in the database and display it in a imagecontrol?
Thanks!!!
 
C

Cor Ligthert [MVP]

Radi,

if (((DataSet)employeesBindingSource.DataSource).HasChanges() ) {
MessageBox.Show("There are changes");

if (northwindDataSet.HasChanges() ) {
MessageBox.Show("There are changes");

Both work fine for me.

I hope this helps,

Cor
 
R

Radi Radichev

Yeah I've tryed this. It still doesn't work correct.. When i change the
record with binding navigator without editing something it still gives me
that there are changes in the dataset... I'm testing it exactly as you
describe:
if(ds.HasChanges())
{
.....
}
Any ideas?
 
C

Cor Ligthert [MVP]

Radi,

Than you should show more code, I gave you two working tested samples, I can
really not look at your code without that you show it to me.

Cor
 
R

Radi Radichev

Oh well here's my code:
private void frmPersonal_FormClosing(object sender, FormClosingEventArgs e)

{

if (this.transcoDataSet.GetChanges()!=null)

{

DialogResult result;

result = MessageBox.Show(this, "blabla", "blablaba",
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button3);

if (result == DialogResult.Yes)

{

this.Validate();

this.personalBindingSource.EndEdit();

this.personalTableAdapter.Update(this.transcoDataSet.personal);

this.transcoDataSet.AcceptChanges();

}

else if (result == DialogResult.No)

e.Cancel = false;

else if (result == DialogResult.Cancel)

e.Cancel = true;

}

}
 
C

Cor Ligthert [MVP]

Radi,

Can you try this one
transcoDataSet.Tables("yourtablename or the strongly typed
one).EndCurrentEdit();
its if(this.transcoDataSet.HasChanges())-----

I hope this helps

Cor
 
R

Radi Radichev

Cor, I can't find such method...
Can you write this a little understandable pls?
 
C

Cor Ligthert [MVP]

Radi,

Has to be brackets, it is a property.
transcoDataSet.Tables["yourtablename"].EndCurrentEdit();

(It was some mix between C# and VBCode at the end I did remember me that you
are using C#)

My keyboard is broken, I have now an old one however while typing with a
broken keyboard I had not much attention to the syntax, I was glad it was
typing.

:)

Cor
 
R

Radi Radichev

When I use the binding source to change the record to the next recort it
automaticly changes somehow the state to modified and when i check it with
HasChanges() it gives me true every time when i look another records.. I
can't find info on this in msdn....
 
R

Radi Radichev

Hehe Cor:)
I know it's a property. I did write it correct.. But there is no such
thing.... You know I'm using .net 2.0 right?
 
R

Radi Radichev

The problem is that i can't move trough the records with the binding
navigator or with the binding source couse they change the RowState to
Modified and there are allways changes when i test the dataset with
HasChanges()!! I can't understand why this is...
 
C

Cor Ligthert [MVP]

Radi,

Sorry this I have sent hundreds of times, as I said malfunction of my
keyboard and therefore probably less attention.

BindingContext[here that table].EndCurrentEdit()

I hope this goes better.

The keyboard I am now using is as well not so good.

Cor
 
C

Cor Ligthert [MVP]

Radi,

As I told, than you should sent the code you use to navigate, now you have
showed to code as that is already done.

Cor
 
R

Radi Radichev

Yeah I found it but where schould i try it? When I update the dataset or
where?


Cor Ligthert said:
Radi,

Sorry this I have sent hundreds of times, as I said malfunction of my
keyboard and therefore probably less attention.

BindingContext[here that table].EndCurrentEdit()

I hope this goes better.

The keyboard I am now using is as well not so good.

Cor



Radi Radichev said:
Hehe Cor:)
I know it's a property. I did write it correct.. But there is no such
thing.... You know I'm using .net 2.0 right?
 
R

Radi Radichev

Hi Cor,
I'm not using any code! I just put a BindingNavigator control and it does
all these things, movenext, prev add new and so on. I tryed to write my own
navigating button with OnClick method like this:
this.personalBinfingSource1.MoveNext();
and it moves through the records but it still changes the state to modified
even if i'm not making any changes only browsing the records... I hope that
it is now clearer what am i doing...
 
C

Cor Ligthert [MVP]

Radi,

That was what I was thinking, I have tested it before and it does not give
changes by me, I have showed the code already to you.

move a position to the next

employeesBindingNavigator.MoveNextItem.PerformClick();


cor
 
R

Radi Radichev

I can't really understand what u mean by that...
what about PerformClick()? it does the same thing..
 
R

Radi Radichev

I'm getting crazy with this one!! It return allways true except when i open
the form do nothing and then clos the form!!!! WHAT COULD BE
WRONG:(((((((((((
 
D

David Sceppa [MSFT]

I'm getting crazy with this one!! It return allways true except when
i open the form do nothing and then clos the form!!!! WHAT COULD BE
WRONG:(((((((((((

The best suggestion I could offer, if you're still struggling with
this issue, is to recreate the problem in a new project using sample
tables, as few controls, and as little code as possible. Assuming you're
still able to reproduce the problem, you're now in a better position to
help others reproduce the problem.

Of course, I'm biased because I'm already crazy.

I hope this information proves helpful.

David Sceppa
Microsoft
This posting is provided "AS IS" with no warranties,
and confers no rights. You assume all risk for your use.
© 2006 Microsoft Corporation. All rights reserved.
 

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