Concurrency error handling

J

John

Hi

I have asked this question before but have not received any clear answer. I
have a winform app with bound controls via dataadapter/dataset combination.I
have a dbconcurrency exception ex. Now I have the following;

DataRow = ex.Row
DataTable = ex.Row.Table
DataColumns = ex.Row.Table.Columns
DataSet = ex.row.Table.Dataset

How can I now via code, do the following;

1. Make a copy of the datarow,

2. Re-read the row from datasource,

3. Update read row with values form row copy.

Any help woudl be appreciated.

Many Thanks

Regards
 
C

Cor Ligthert[MVP]

John,

All your three questions are impossible to do.
1. Make a copy of the datarow,
A datarow is a collection of objects that exist partially in the datarow
itself as item collection and partially in the datatable columns collection.
2. Re-read the row from datasource,
You never need to re-read the row from a datasource as you haven't
overwritten it.

3. Update read row with values form row copy.
As long as you don't reset your concurrency protection, you would not be
able to overwrite it with whatever you want, but if you want to do that, you
simple use the original row and disable the concurrency checking.

Cor
 
C

Cor Ligthert[MVP]

Hi John,

I thought that I had answered you, however I don't see my answer

:)

Have a look at the SQL code for the update in your program or stored
procedures where is written something as.

Select TimeStamp from Table

If TimeStamp = @TimeStamp
Begin and then the update transaction in SQL .

As you delete that part, then the SQL code will probably eat everything you
deliver to it.

(It can also be a range of old values, compared with the new selected
existing values)

(It is probably easier to write the Update SQL yourself new by hand and than
skip the Select of the current values or current tinestamp)

Cor
 
J

John

Hi Cor

I have the below Update SP (slightly simplified to exclude irrelevant
columns);

UPDATE [dbo].[Clients] SET [Company] = @Company, [Address 1] = @Address_1
WHERE (([ID] = @Original_ID) AND ([SSMA_TimeStamp] =
@Original_SSMA_TimeStamp));
SELECT ID, Company, [Address 1] SSMA_TimeStamp FROM Clients WHERE (ID = @ID)

Ideally on concurrency violation I would like to give user option to force
save or cancel save. What would be the mechanism for that? My applications
is a vb.net winform app.

Many Thanks

Regards
 
C

Cor Ligthert[MVP]

John,

Then create an extra Update where that WHERE clause part from the timestamp
from the one you show now is deleted.

I can not tell you how to do it in VB as I don't know what you use to update
in that, it can be an execute nonquery or a xxAdapter. Those you have of
course to make new, or simple set the right update sql to its command every
time you use the original or the overwritting one.


However be aware what you doing, as this can give big errors.
(There is a sample in banking busines where this was used to fraud).

Cor

John said:
Hi Cor

I have the below Update SP (slightly simplified to exclude irrelevant
columns);

UPDATE [dbo].[Clients] SET [Company] = @Company, [Address 1] = @Address_1
WHERE (([ID] = @Original_ID) AND ([SSMA_TimeStamp] =
@Original_SSMA_TimeStamp));
SELECT ID, Company, [Address 1] SSMA_TimeStamp FROM Clients WHERE (ID =
@ID)

Ideally on concurrency violation I would like to give user option to force
save or cancel save. What would be the mechanism for that? My applications
is a vb.net winform app.

Many Thanks

Regards

Cor Ligthert said:
Hi John,

I thought that I had answered you, however I don't see my answer

:)

Have a look at the SQL code for the update in your program or stored
procedures where is written something as.

Select TimeStamp from Table

If TimeStamp = @TimeStamp
Begin and then the update transaction in SQL .

As you delete that part, then the SQL code will probably eat everything
you
deliver to it.

(It can also be a range of old values, compared with the new selected
existing values)

(It is probably easier to write the Update SQL yourself new by hand and
than
skip the Select of the current values or current tinestamp)

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