|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Concurrency violationI change the value in the Datagridview and then update using
Data adapter update method and I am getting Message="Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.†I am the only user in the SQL database. How can I solve this problem. How do turn off optimistic concurrency. Thanks HGJ This means you executed an Update statement and the SQL executed (that you
coded or the VS tools built for you) either changed more than one row or 0 rows. I suggest you check out the advanced options in the TableAdapter Configuration wizard (as I discuss in my book in Chapter 6) to disable the code generation. However, this also removes the code used to update the data. Yes, you have choices when it comes to update concurrency, but you have to know what you're doing to use them... -- Show quote____________________________________ William (Bill) Vaughn Author, Mentor, Consultant Microsoft MVP INETA Speaker www.betav.com/blog/billva www.betav.com Please reply only to the newsgroup so that others can benefit. This posting is provided "AS IS" with no warranties, and confers no rights. __________________________________ Visit www.hitchhikerguides.net to get more information on my latest book: Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition) and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) ----------------------------------------------------------------------------------------------------------------------- "HGJ" <H**@discussions.microsoft.com> wrote in message news:EB60627D-DF35-4B30-8398-F13B6265CF44@microsoft.com... >I change the value in the Datagridview and then update using > Data adapter update method and I am getting > Message="Concurrency violation: the UpdateCommand affected 0 of the > expected > 1 records." > I am the only user in the SQL database. > How can I solve this problem. > How do turn off optimistic concurrency. > > Thanks > HGJ > > Hi Bill,
Thanks for y our reply. I would like to know how to programmatically turn off optimistic concurrency. Thanks Harry Show quote "William (Bill) Vaughn" wrote: > This means you executed an Update statement and the SQL executed (that you > coded or the VS tools built for you) either changed more than one row or 0 > rows. I suggest you check out the advanced options in the TableAdapter > Configuration wizard (as I discuss in my book in Chapter 6) to disable the > code generation. However, this also removes the code used to update the > data. Yes, you have choices when it comes to update concurrency, but you > have to know what you're doing to use them... > > -- > ____________________________________ > William (Bill) Vaughn > Author, Mentor, Consultant > Microsoft MVP > INETA Speaker > www.betav.com/blog/billva > www.betav.com > Please reply only to the newsgroup so that others can benefit. > This posting is provided "AS IS" with no warranties, and confers no rights. > __________________________________ > Visit www.hitchhikerguides.net to get more information on my latest book: > Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition) > and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) > ----------------------------------------------------------------------------------------------------------------------- > > "HGJ" <H**@discussions.microsoft.com> wrote in message > news:EB60627D-DF35-4B30-8398-F13B6265CF44@microsoft.com... > >I change the value in the Datagridview and then update using > > Data adapter update method and I am getting > > Message="Concurrency violation: the UpdateCommand affected 0 of the > > expected > > 1 records." > > I am the only user in the SQL database. > > How can I solve this problem. > > How do turn off optimistic concurrency. > > > > Thanks > > HGJ > > > > > > > Ah, it's not a "programmatic" thing really that can be switched on and off.
The choices between concurrency options is made by Visual Studio's code generators as you work interactively with the TableAdapter Configuration wizard (as I describe in the book), OR by the code you write to implement concurrency. What is it that you're trying to do? Simply write the rows to the database? If this is the case, I think it would be easier to write your own UpdateCommand, InsertCommand and DeleteCommand and code them as needed. Most developers evolve to that point at one point in time or another. hth -- Show quote____________________________________ William (Bill) Vaughn Author, Mentor, Consultant Microsoft MVP INETA Speaker www.betav.com/blog/billva www.betav.com Please reply only to the newsgroup so that others can benefit. This posting is provided "AS IS" with no warranties, and confers no rights. __________________________________ Visit www.hitchhikerguides.net to get more information on my latest book: Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition) and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) ----------------------------------------------------------------------------------------------------------------------- "HGJ" <H**@discussions.microsoft.com> wrote in message news:FE6E30F0-D50E-484A-A3E9-F52DBBC594B0@microsoft.com... > Hi Bill, > Thanks for y our reply. > I would like to know how to programmatically turn off optimistic > concurrency. > Thanks > Harry > > > > "William (Bill) Vaughn" wrote: > >> This means you executed an Update statement and the SQL executed (that >> you >> coded or the VS tools built for you) either changed more than one row or >> 0 >> rows. I suggest you check out the advanced options in the TableAdapter >> Configuration wizard (as I discuss in my book in Chapter 6) to disable >> the >> code generation. However, this also removes the code used to update the >> data. Yes, you have choices when it comes to update concurrency, but you >> have to know what you're doing to use them... >> >> -- >> ____________________________________ >> William (Bill) Vaughn >> Author, Mentor, Consultant >> Microsoft MVP >> INETA Speaker >> www.betav.com/blog/billva >> www.betav.com >> Please reply only to the newsgroup so that others can benefit. >> This posting is provided "AS IS" with no warranties, and confers no >> rights. >> __________________________________ >> Visit www.hitchhikerguides.net to get more information on my latest book: >> Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition) >> and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) >> ----------------------------------------------------------------------------------------------------------------------- >> >> "HGJ" <H**@discussions.microsoft.com> wrote in message >> news:EB60627D-DF35-4B30-8398-F13B6265CF44@microsoft.com... >> >I change the value in the Datagridview and then update using >> > Data adapter update method and I am getting >> > Message="Concurrency violation: the UpdateCommand affected 0 of the >> > expected >> > 1 records." >> > I am the only user in the SQL database. >> > How can I solve this problem. >> > How do turn off optimistic concurrency. >> > >> > Thanks >> > HGJ >> > >> > >> >> >> Bill thank you very much for you quick respond.
This is my update command daTSheet.UpdateCommand.CommandText = "UPDATE TimeSheetDetail " & _ "SET JobNumber = left(@JobNumber,7), hrsType=left(@hrsType,1)," & _ "Day01=@Day01 ," & _ "Day02=@Day02, Day03=@Day03, Day04=@Day04, Day05=@Day05, Day06=@Day06, " & _ "Day07=@Day07, Day08=@Day08, Day09=@Day09, Day10=@Day10, Day11=@Day11, " & _ "Day12=@Day12, Day13=@Day13, Day14=@Day14, Day15=@Day15, Day16=@Day16 " & _ "WHERE TimeSheetID = @TimeSheetID and JobNumber = @JobNumber " & _ "and hrsType = @hrsType" Save statement is: daTSheet.Update(dsTSheet.Tables("TSheets")) When I change any DayXX value and save it works fine, but when I change JobNumber or hrsType and save I get “Concurrency violation†error I don’t know how to fix it. Thanks for your support. HGJ You deleted the rest of the thread... which makes it harder to reply. ;(
Ok, I assume this UpdateCommand is something you generated? In any case, you can't change the primary key in an update. That, (by definition) is a delete and insert. All of the PK columns (you seem to have several) should be RO in the UI elements. If you do need to change these, you need to setup a new add/delete mechanism to do so. hth -- Show quote____________________________________ William (Bill) Vaughn Author, Mentor, Consultant Microsoft MVP INETA Speaker www.betav.com/blog/billva www.betav.com Please reply only to the newsgroup so that others can benefit. This posting is provided "AS IS" with no warranties, and confers no rights. __________________________________ Visit www.hitchhikerguides.net to get more information on my latest book: Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition) and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) ----------------------------------------------------------------------------------------------------------------------- "HGJ" <H**@discussions.microsoft.com> wrote in message news:A4D671E9-ACAA-4864-B7D0-E7304EF0DA48@microsoft.com... > Bill thank you very much for you quick respond. > > This is my update command > > daTSheet.UpdateCommand.CommandText = "UPDATE TimeSheetDetail " & _ > "SET JobNumber = left(@JobNumber,7), hrsType=left(@hrsType,1)," & _ > "Day01=@Day01 ," & _ > "Day02=@Day02, Day03=@Day03, Day04=@Day04, Day05=@Day05, Day06=@Day06, " & > _ > "Day07=@Day07, Day08=@Day08, Day09=@Day09, Day10=@Day10, Day11=@Day11, " & > _ > "Day12=@Day12, Day13=@Day13, Day14=@Day14, Day15=@Day15, Day16=@Day16 " & > _ > "WHERE TimeSheetID = @TimeSheetID and JobNumber = @JobNumber " & _ > "and hrsType = @hrsType" > > Save statement is: daTSheet.Update(dsTSheet.Tables("TSheets")) > > When I change any DayXX value and save it works fine, but when I change > JobNumber or hrsType and save I get "Concurrency violation" error I don't > know how to fix it. > > Thanks for your support. > HGJ > |
|||||||||||||||||||||||