DataTable changes...

Arg81

Well-known member
Joined
Mar 11, 2005
Messages
949
Location
Midlands, UK
Programming Experience
1-3
Is there a way I can check to see whether a datatable has had changes made?

I did try
VB.NET:
if me.dataSet1.haschanges() Then
messagebox.show("Changes!")
Else
messagebox.show("No Changes!")

but even if I change the values in the grid, I still get told No Changes...

I've got a panel that is also bound to the data on the grid, and this is shown when a user clicks "Edit". On the panel, the user can only click "cancel" and "Submit".
I've got a bit of code that I want to fire off ONLY IF the user has made any changes to the data on that panel and clicks "Submit".
If the user clicks Submit without changing any of the data, I don't want the code to be fired....

Thanks
 
Assuming that your datatable is a member of the datatable collection of the dataset you are calling HasChanges on then i can't see why that code won't execute as expected. Are changes actually being made?

Another method would be to use the Datatable.GetChanges Methods and check the Rows.Count property of the returned datatable. If it is null then no changes have been made.
 
Yeah I've seen that .getchanges() code before in a book when I was learning but haven't really ever used it...

Yep, the table I'm editing is in the dataSet I'm calling .haschanges() on.

Changes I make to the panel are shown in the datagrid...it has confused me as I thought I was doing it right but obviously something somewhere is wrong...
 
VB.NET:
If me.dsDevelopment.HasChanges() Then
[SIZE=2][COLOR=#0000ff]    
    Me[/COLOR][/SIZE][SIZE=2].DWRRevisionBindingSource.EndEdit()
[/SIZE][SIZE=2][COLOR=#0000ff]    Me[/COLOR][/SIZE][SIZE=2].DWR_RevisionTableAdapter.Update([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].DsDevelopment.DWR_Revision)[/SIZE]
[SIZE=2]    [B][COLOR=seagreen]'THIS IS WHERE I WILL RUN MY EMAIL CODE[/COLOR][/B]
[/SIZE][SIZE=2][COLOR=#0000ff]    Me[/COLOR][/SIZE][SIZE=2].DWRRevisionBindingSource.Sort = [/SIZE][SIZE=2][COLOR=#a31515]"RevisionNumber DESC"
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]    Me[/COLOR][/SIZE][SIZE=2].grdRevision.MoveFirst()[/SIZE]
    Me.panel1.hide()
[SIZE=2]Else[/SIZE]
    Me.panel1.hide()

 
Ahhh, missed that in your previous post.

VB.NET:
Me.DWRRevisionBindingSource.EndEdit()

The above line needs to be placed BEFORE you make a call to HasChanges otherwise the Current RowState will not be modified which is how HasChanges determines if changes have been made.
 

Latest posts

Back
Top