Method GetChanges and closing event

  • Thread starter Thread starter Tore Gylver
  • Start date Start date
T

Tore Gylver

I have a windows form bound to a dataset. The dataset is
populated from a webservice. The dataset contains 2
tables. The dataset table that is bound to the form has
only one single row.

The operator updates data via textboxes on the form.
I have a SAVE button on the form that invokes GetChanges
on the dataset. The dataset and the source (webservice)
is updated. It works fine.

If the operator forgets to save I catch this in the forms
closing event (Dataset.HasChanges), stop the closing and
give a warning to the operator.

Then the problem arises. After the closing event is
stopped (by e.cancel set to TRUE) and the operator then
press the SAVE-button, the dataset behaves differently.

I ask for the changes:

DiffOrder = (DS_OrderGet.GetChanges
(DataRowState.Modified))

DS_OrderGet is the dataset that is bound to the form,
Difforder is a dataset of the same type.

After the cancelled closing event dataset Difforder gets
the original content from DS_OrderGet, before the user
started his update of the form.

(When the operator presses the SAVE button before the
closing event, the codeline works as expected, Dataset
Difforder gets the changes)

The "getChanges" seem to be the problem. I have figured
out a solution where I gave up "GetChanges" of
DS_OrderGet. I just updated the webservice using the
total DS_OrderGet as source. DS_OrderGet contains the
updated datarow in both cases, while Difforder does not.
My solution works fine since it is only one row in the
dataset, but would be very impractical with many rows.

Can anyone provide me with the codelines
using "GetChanges" and a "differential" dataset that will
work in both cases?

The dataset is in a baseform and the Save button in an
inherited form, but I dont think this is the reason for
the problem.

Regards

Tore Gylver
 
Tore,
I may not be able to help you but you might be able to
help me. When you click on the save button you say that
you getchanges...
I am trying to update a single record file using a windows
form. The data already exist in the table but my user may
want to change it.
I can display the data via the dataset and the fields are
bound, however after the user changes the data and clicks
on the close button my problem starts.
I have tried using the sqldataadapter.update
(dataset,"tableName")
but it does not update the orginal table, nor does it give
me an exception...
Any chance you could give me a short bit of code of how
you did it?
I am new at this...
:)Bruce...
 
Hi Tore,

I'm trying to repro your problem on my machine, however, I'm not clear
about what the different behavior did you refer to? Could you show me some
code snippet of your closing event handler and the save button event
handler? And I'd like to know if there is some other controls on your form,

Just a guess, Try adding this statement ,

BindingContext[dataSet11,"Categories"].EndCurrentEdit();

before you calling the GetChanges, will it solve your problem?

Thanks!


Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending.

--------------------
| Content-Class: urn:content-classes:message
| From: "Tore Gylver" <[email protected]>
| Sender: "Tore Gylver" <[email protected]>
| Subject: Method GetChanges and closing event
| Date: Wed, 12 Nov 2003 01:50:34 -0800
| Lines: 53
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcOpAmsftLtF0nMFTXSulzQRR6/X4g==
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:56345
| NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| I have a windows form bound to a dataset. The dataset is
| populated from a webservice. The dataset contains 2
| tables. The dataset table that is bound to the form has
| only one single row.
|
| The operator updates data via textboxes on the form.
| I have a SAVE button on the form that invokes GetChanges
| on the dataset. The dataset and the source (webservice)
| is updated. It works fine.
|
| If the operator forgets to save I catch this in the forms
| closing event (Dataset.HasChanges), stop the closing and
| give a warning to the operator.
|
| Then the problem arises. After the closing event is
| stopped (by e.cancel set to TRUE) and the operator then
| press the SAVE-button, the dataset behaves differently.
|
| I ask for the changes:
|
| DiffOrder = (DS_OrderGet.GetChanges
| (DataRowState.Modified))
|
| DS_OrderGet is the dataset that is bound to the form,
| Difforder is a dataset of the same type.
|
| After the cancelled closing event dataset Difforder gets
| the original content from DS_OrderGet, before the user
| started his update of the form.
|
| (When the operator presses the SAVE button before the
| closing event, the codeline works as expected, Dataset
| Difforder gets the changes)
|
| The "getChanges" seem to be the problem. I have figured
| out a solution where I gave up "GetChanges" of
| DS_OrderGet. I just updated the webservice using the
| total DS_OrderGet as source. DS_OrderGet contains the
| updated datarow in both cases, while Difforder does not.
| My solution works fine since it is only one row in the
| dataset, but would be very impractical with many rows.
|
| Can anyone provide me with the codelines
| using "GetChanges" and a "differential" dataset that will
| work in both cases?
|
| The dataset is in a baseform and the Save button in an
| inherited form, but I dont think this is the reason for
| the problem.
|
| Regards
|
| Tore Gylver
|
 
Thank you. Your codeline did the work after some
modification. I ended up with a codeline like this:

DS_OrderGet2.PSP_OrderGet.Rows(0).EndEdit()

DS_OrderGet2 is the dataset that is bound to the windows
form.
PSP_OrderGet is the stored procedure that is the source
of the dataset in a webservice.

My "SaveChanges" procedure is listed below, and now it
works both before and after cancel of the forms closing
event. I still dont understand why I need "EndEdit"
codeline in one case and not in the other. But it works
anyway, thank you.

Here is my code:

Protected Friend Sub SaveChanges()
If DS_OrderGet2.HasChanges() Then
Dim ws As New WinStartup.localhost2.OrderGet
ws.Credentials =
System.Net.CredentialCache.DefaultCredentials
Dim DS_DiffOrder As New
WinStartup.localhost2.DS_OrderGet

DS_OrderGet2.PSP_OrderGet.Rows(0).EndEdit()
DS_DiffOrder.Merge(DS_OrderGet2.GetChanges
(DataRowState.Modified))

MsgBox(DS_DiffOrder.PSP_OrderGet.Rows(0).Item
("ordername")) 'Used for test
DS_DiffOrder = ws.OrderUpdate(DS_DiffOrder,
CInt(Me.TextOrderID.Text))
DS_OrderGet2.Merge(DS_DiffOrder)
DS_OrderGet2.AcceptChanges()

End If

End Sub


Regards

Tore


-----Original Message-----
Hi Tore,

I'm trying to repro your problem on my machine, however, I'm not clear
about what the different behavior did you refer to? Could you show me some
code snippet of your closing event handler and the save button event
handler? And I'd like to know if there is some other controls on your form,

Just a guess, Try adding this statement ,

BindingContext[dataSet11,"Categories"].EndCurrentEdit();

before you calling the GetChanges, will it solve your problem?

Thanks!


Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending.

--------------------
| Content-Class: urn:content-classes:message
| From: "Tore Gylver" <[email protected]>
| Sender: "Tore Gylver" <[email protected]>
| Subject: Method GetChanges and closing event
| Date: Wed, 12 Nov 2003 01:50:34 -0800
| Lines: 53
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcOpAmsftLtF0nMFTXSulzQRR6/X4g==
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:56345
| NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| I have a windows form bound to a dataset. The dataset is
| populated from a webservice. The dataset contains 2
| tables. The dataset table that is bound to the form has
| only one single row.
|
| The operator updates data via textboxes on the form.
| I have a SAVE button on the form that invokes GetChanges
| on the dataset. The dataset and the source (webservice)
| is updated. It works fine.
|
| If the operator forgets to save I catch this in the forms
| closing event (Dataset.HasChanges), stop the closing and
| give a warning to the operator.
|
| Then the problem arises. After the closing event is
| stopped (by e.cancel set to TRUE) and the operator then
| press the SAVE-button, the dataset behaves differently.
|
| I ask for the changes:
|
| DiffOrder = (DS_OrderGet.GetChanges
| (DataRowState.Modified))
|
| DS_OrderGet is the dataset that is bound to the form,
| Difforder is a dataset of the same type.
|
| After the cancelled closing event dataset Difforder gets
| the original content from DS_OrderGet, before the user
| started his update of the form.
|
| (When the operator presses the SAVE button before the
| closing event, the codeline works as expected, Dataset
| Difforder gets the changes)
|
| The "getChanges" seem to be the problem. I have figured
| out a solution where I gave up "GetChanges" of
| DS_OrderGet. I just updated the webservice using the
| total DS_OrderGet as source. DS_OrderGet contains the
| updated datarow in both cases, while Difforder does not.
| My solution works fine since it is only one row in the
| dataset, but would be very impractical with many rows.
|
| Can anyone provide me with the codelines
| using "GetChanges" and a "differential" dataset that will
| work in both cases?
|
| The dataset is in a baseform and the Save button in an
| inherited form, but I dont think this is the reason for
| the problem.
|
| Regards
|
| Tore Gylver
|

.
 
Back
Top