473,748 Members | 5,429 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Concurrency Violation

I have a DataTable which I did use as the source for a DataGrid, teh data
table was popeulated form my database and when I made changes in the grid I
used the same DataAdapter to chnage the values in the database.

However, I now have the need (on a column by column basis) to show the
values in the grid as a multiple of what is in the underlying datatable.
Then if the user edits the grid I must then devide by the same value before
updating the database again.

My first effort for this was to have a DataTable representing the data in
the database and another DataTable representing the data in the DataGrid.
The before displaying any data in the grid or updating the database I would
execute a function that copies (using ImportRow) each row from the display
DataTable to the storage DataTable converting values as necessary as we go
along. This seemed OK and each row kept the expected RowState.

However, after I copy from the display DataTable to the storage DataTable
and use the DataAdapter.Upd ate method on the storage DataTable to put the
changes back into the database I get the following error:

concurrency violation: the updatecommand affected 0 records

so it looks like I cannot accomplish what I am trying to do with two
DataTables.. or can I? Or is there an easier way to do this? I know it looks
stramge but I do have a valid requirement to do this.

TIA
Nov 21 '05 #1
4 1240
Hi,

Take a look at the datatables getchages method.

http://msdn.microsoft.com/library/de...angestopic.asp

Ken
------------------------
"elziko" <el****@NOTSPAM MINGyahoo.co.uk > wrote in message
news:uZ******** *****@TK2MSFTNG P09.phx.gbl...
I have a DataTable which I did use as the source for a DataGrid, teh data
table was popeulated form my database and when I made changes in the grid I
used the same DataAdapter to chnage the values in the database.

However, I now have the need (on a column by column basis) to show the
values in the grid as a multiple of what is in the underlying datatable.
Then if the user edits the grid I must then devide by the same value before
updating the database again.

My first effort for this was to have a DataTable representing the data in
the database and another DataTable representing the data in the DataGrid.
The before displaying any data in the grid or updating the database I would
execute a function that copies (using ImportRow) each row from the display
DataTable to the storage DataTable converting values as necessary as we go
along. This seemed OK and each row kept the expected RowState.

However, after I copy from the display DataTable to the storage DataTable
and use the DataAdapter.Upd ate method on the storage DataTable to put the
changes back into the database I get the following error:

concurrency violation: the updatecommand affected 0 records

so it looks like I cannot accomplish what I am trying to do with two
DataTables.. or can I? Or is there an easier way to do this? I know it looks
stramge but I do have a valid requirement to do this.

TIA

Nov 21 '05 #2
>Take a look at the datatables getchages method.

Thanks for your reply but I don't understand how this helps me. Looking at
the RowStates there are a couple of rows that are modified and this would be
given in the DataTable that is returned from GetChanges. The problem is that
when the DataAdapter tries to update these changes to the database I get a
concurrency exception.

I think the reason for this is that the DataTable I am using for the
DataAdapter.Upd ate isnt the same as the one I used for the DataAdapter.Fil l.
It is actually a new DataTable containing imported rows from teh original.
Here is some code that describes it.

Firstly when getting data from the database:

da.Fill(dtStora ge)
dtDisplay = New DataTable
intRowNumber = 0
For Each dr As DataRow In dtStorage.Rows
dtDisplay.Impor tRow(dr)
dtDisplay.Rows( intRowNumber).I tem(0) =
Convert.ToSingl e(dtDisplay.Row s(intRowNumber) .Item(0)) * 10
intRowNumber += 1
Next

That works fine but then when I try and update the database with any values
from the grid:

dtStorage = New DataTable
intRowNumber = 0
For Each dr As DataRow In dtDisplay.Rows
dtStorage.Impor tRow(dr)
dtStorage.Rows( intRowNumber).I tem(0) =
Convert.ToSingl e(dtStorage.Row s(intRowNumber) .Item(0)) / 10
intRowNumber += 1
Next
da.Update(dtSto rage)

I get the concurremcy exception. As you see in my example the value for the
first column is always displayed as ten time slarger than whats in the
database. This is the value that the user sees and edits but before teh
database is updated the value is decreased by a factor of ten for storage.
Is there any way around my problem?
Nov 21 '05 #3
Hi,

Not sure why you need 2 tables but. You forgot the begin and
end edit before you chaged the values in the loop.

dtStorage.Rows( intRowNumber).I tem(0).beginedi t
dtStorage.Rows( intRowNumber).I tem(0) =
Convert.ToSingl e(dtStorage.Row s(intRowNumber) .Item(0)) / 10
dtStorage.Rows( intRowNumber).I tem(0).endedit

http://msdn.microsoft.com/library/de...nedittopic.asp

Ken
---------------------
"elziko" <el****@NOTSPAM MINGyahoo.co.uk > wrote in message
news:uW******** ******@TK2MSFTN GP09.phx.gbl...
Take a look at the datatables getchages method.


Thanks for your reply but I don't understand how this helps me. Looking at
the RowStates there are a couple of rows that are modified and this would be
given in the DataTable that is returned from GetChanges. The problem is that
when the DataAdapter tries to update these changes to the database I get a
concurrency exception.

I think the reason for this is that the DataTable I am using for the
DataAdapter.Upd ate isnt the same as the one I used for the DataAdapter.Fil l.
It is actually a new DataTable containing imported rows from teh original.
Here is some code that describes it.

Firstly when getting data from the database:

da.Fill(dtStora ge)
dtDisplay = New DataTable
intRowNumber = 0
For Each dr As DataRow In dtStorage.Rows
dtDisplay.Impor tRow(dr)
dtDisplay.Rows( intRowNumber).I tem(0) =
Convert.ToSingl e(dtDisplay.Row s(intRowNumber) .Item(0)) * 10
intRowNumber += 1
Next

That works fine but then when I try and update the database with any values
from the grid:

dtStorage = New DataTable
intRowNumber = 0
For Each dr As DataRow In dtDisplay.Rows
dtStorage.Impor tRow(dr)
dtStorage.Rows( intRowNumber).I tem(0) =
Convert.ToSingl e(dtStorage.Row s(intRowNumber) .Item(0)) / 10
intRowNumber += 1
Next
da.Update(dtSto rage)

I get the concurremcy exception. As you see in my example the value for the
first column is always displayed as ten time slarger than whats in the
database. This is the value that the user sees and edits but before teh
database is updated the value is decreased by a factor of ten for storage.
Is there any way around my problem?

Nov 21 '05 #4
Elziko,

I think that you will have more benefit by using extra columns in your
datatable.
You can add as much columns as you wish and even have expressions for that,
only the correct named columns will be updated.

Just my thought,

Cor
Nov 21 '05 #5

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

Similar topics

2
2164
by: Billy Jacobs | last post by:
I have a client who is getting a concurrency violation error whenever she tries to update a record. I can log in to the site as her simultaneously and update the record with no problem. I can even open 2 browsers at the same time and click the update on one and then the other with no problems. Any help would be appreciated.
3
2446
by: Suzanne | last post by:
Hi All I'm having problems getting my data adapter to throw a concurrency exception with an INSERT command. I want to throw a concurrency exception if an attempt is made to enter a row into tb_table when a row with the same int_UID already exists in there. Here is my stored procedure: if not exists (select int_UID from tb_table where int_UID = @aint_UID)
25
2428
by: nick | last post by:
I'm having trouble updating from a datagrid. It's says "Concurrency violation: the UpdateCommand affected 0 records", though I can't see how it's related to "concurrency". I can insert and delete with no problem. Here's the code that's causing the problem: public void UpdateDataSource(Dancers.allbookings ChangedRows) { try { if ((ChangedRows != null))
2
5266
by: Niyazi | last post by:
Hi, I have not understand the problem. Before all the coding with few application everything worked perfectly. Now I am developing Cheque Writing application and when the cheque is clear the user have to open a form and entera date so we know in report that the desiered check has been cleared. It takes me while to wrtie. But when I try to update the datagrid changes via dataset to MS Access 2003 I get an error that simply says...
4
3830
by: Steven Nagy | last post by:
Hi Have a problem that consistantly occurs in my applications where using a DataAdapter (OLEDB) and a dataset. Using a simple process of adding a row to the dataset table and then calling the dataAdapter.Update method. The row adds. However if I delete that new row immediately via the dataset, I get a concurrency violation. By deleting via dataset, I mean, dataset.table(rownum).Delete() then once again calling the
2
3239
by: Vladimir O¾ura | last post by:
I am building a pocket pc application that requires a datagrid. I am inserting a new row this way: private void mInsert_Click(object sender, System.EventArgs e) { try { DataRow dr = this.ldb.DohvatiDataSet.Tables.NewRow(); dr.BeginEdit();
4
2266
by: Jerry | last post by:
Hi, I have an app which retrieves data from a sql server table and displays it on a datagrid. If 2 sessions of this app are running and 2 users try to update the same record at about the same time, one of the apps will yield a concurrency violation error. The app with the error will have a little red error symbol next to the record in the datagrid, and the only way I can make the error go away for now is to restart that session. Is...
2
2550
by: Agnes | last post by:
I got a simple form and using databinding manager to do the add new Now , my big trobule is . I can update the 'addnew' record, However, after I new the record, and then amend it , it got concurrency violation error, (I can solve it but I need to clear the dataset and fill in again, and I think it is not the solution) Please help -- ..
2
3488
by: BobAchgill | last post by:
Do you know why this error might be happening? Maybe it is because I have two data adapters open on the same MDB file?? If this is the problem... how can I keep them from disturbing each other? An unhandled exception of type 'System.Data.DBConcurrencyException' occurred in system.data.dll Additional information: Concurrency violation: the
5
31422
by: Vayse | last post by:
In my save code, most of items save fine. But sometimes I get a concurrency violation message. "Concurrency violation: the UpdateCommand affected 0 of the expected 1 records." It happens on the same records each time - once this happens, it never saves ok again. The immediate window also has states: A first chance exception of type 'System.Data.DBConcurrencyException' occurred in System.Data.dll
0
9534
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9241
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8239
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3303
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2777
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.