473,320 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Datagrid and dataset 'haschanges' problem

I create a dataset, load xmlfile, create dataview (ds.defaultview) and
bind it to a datagrid (dataset haschanges property is now 'true').
When a user closes the form I want to check via ds.haschanges if there
are pending changes in the dataset. Now returns 'true' always.
When I say 'acceptchanges' after loading the xmlfile, the haschanges
always says 'false' when closing the form.
Guess I'm missing something. Alternative solution to check for pending
changes when closing the form is also fine.

Jul 21 '05 #1
4 5017
Thread,

No you are missing nothing, acceptchanges mean set all datarows to the
rowstate unchanged.

I hope this helps,

Cor
Jul 21 '05 #2
Okay, let's try to make my problem clear. Here are the form load en
close events. Reason I use a dataview is that I won't allow the user to
add a new record.
My problem is that using 'haschanges' is not reliable for the purpose I
use it for.

Private Sub frmEditOptions_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
ds1.ReadXml(gstrFile)
Dim dv As New DataView
dv = ds1.Tables("Options").DefaultView()
dv.AllowNew = False
With DataGrid1
.DataSource = dv
.CaptionText = "Options"
End With
End Sub

Private Sub frmEditOptions_Closing(ByVal sender As Object, ByVal e
As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Dim s As String
If ds1.HasChanges() Then
If MsgBox("Wijzigingen opslaan?", MsgBoxStyle.YesNo +
MsgBoxStyle.Question) = MsgBoxResult.Yes Then
WriteXmlToFile(ds1, gstrFile)
End If
End If
End Sub

Jul 21 '05 #3
Okay, let's try to make my problem clear. Here are the form load en
close events. Reason I use a dataview is that I won't allow the user to

add a new record. My problem is that using 'haschanges' is not reliable
for the purpose I use it for.

dim ds1 as new dataset
Private Sub frmEditOptions_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
ds1.ReadXml(gstrFile)
Dim dv As New DataView
dv = ds1.Tables("Options").DefaultV*iew()
dv.AllowNew = False
With DataGrid1
.DataSource = dv
.CaptionText = "Options"
End With
End Sub
Private Sub frmEditOptions_Closing(ByVal sender As Object, ByVal e
As System.ComponentModel.CancelEv*entArgs) Handles MyBase.Closing
Dim s As String
If ds1.HasChanges() Then
If MsgBox("Wijzigingen opslaan?", MsgBoxStyle.YesNo +
MsgBoxStyle.Question) = MsgBoxResult.Yes Then
WriteXmlToFile(ds1, gstrFile)
End If
End If
End Sub


Cor Ligthert schreef:
Thread,

No you are missing nothing, acceptchanges mean set all datarows to the
rowstate unchanged.

I hope this helps,

Cor


Jul 21 '05 #4
Ad,

I don't see what there is wrong and I see only a small part of your code,
however probably the last changed row will not be updated, therefore I would
add something as
Private Sub frmEditOptions_Closing(ByVal sender As Object, ByVal e
As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Dim s As String
BindingContext(ds1.Tables("Options").EndCurrentEdi t()
If ds1.HasChanges() Then
If MsgBox("Wijzigingen opslaan?", MsgBoxStyle.YesNo +
MsgBoxStyle.Question) = MsgBoxResult.Yes Then
WriteXmlToFile(ds1, gstrFile)
End If
End If
End Sub


I hope this helps

Cor
Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Michael Dimento | last post by:
I'm trying to detect if there are any unsaved changes in a dataset when a user hits close form button (top right hand corner). My problem is that HasChanges does not detect a row that has been...
6
by: BFX | last post by:
Hi All, I have datagrid with binding on dataset this.grdMachineType.DataMember = "MachineTypes"; this.grdMachineType.DataSource = this.dsMachineTypes; After append new row in datagrid i...
0
by: TK | last post by:
Hi, I need help on datagrid. I have a dataset exposed as a webservice. I do have a web application that is supposed to consume the service on a datagrid.
3
by: matthew schouppe | last post by:
I have a datagrid with two columns, the first a normal bound column, the second is a template column created from a bound column. For the ItemTemplate of the Template Column, I removed the label...
0
by: Geraldine Hobley | last post by:
Hello, I have a problem whereby I have datagrid bound to a dataset with the following properties I have put a similar problem up b4 but I still do not have an answer. MyDatagrid.DataSource =...
6
by: Jan Nielsen | last post by:
Hi I asked this question some weeks ago, but have found no soluion yet, so I try again I have a parent detail relationship between two tables. The detail records are shown in a datagrid...
3
by: Jim | last post by:
I have a datagrid with a DataAdapter as the DataSource. The user fills in their data for 3 columns and I want to programically add a value to the 4th (invisible) column (employee number). That way...
4
by: thead01 | last post by:
I create a dataset, load xmlfile, create dataview (ds.defaultview) and bind it to a datagrid (dataset haschanges property is now 'true'). When a user closes the form I want to check via...
3
by: John Sheppard | last post by:
Hello there, I have the following code; I do this as a work around for a dataset.haschanges method which doesnt appear to work correctly either For Each dt As DataTable In myDs.Tables If Not...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.