oucanmodifythegeneratedcommandtextsoitdoesnothavetocheckeveryoriginalvalueagainstthevaluesinthedatasource.Themostcommonwaytoaccomplishthisiswithatimestamporversionfield.Ifyourdatacontainsatimestampfieldthatisupdatedeverytimethedatachanges,youneedonlycheckthetimestampinyourapplication'srecordagainstthetimestampinthedatasourcetodetermineifaconcurrentuserhaschangedtherecord.
ThefollowingSQLstatementhasbeenmodifiedtocheckthetimestamp.
NoteThisexamplepresumesthetimestamphasbeengeneratedinthedatabase.
UPDATECustomersSETCustomerID=@CustomerID,CompanyName=@CompanyName,
ContactName=@ContactName,ContactTitle=@ContactTitle,City=@City
WHERE(CustomerID=@Original_CustomerID)AND
(TimeStamp=@Original_TimeStamp);
SELECTCustomerID,CompanyName,ContactName,ContactTitle,City,
TimeStampFROMCustomersWHERE(CustomerID=@CustomerID)
ConcurrencyandCommand-BuilderObjects
IfyourapplicationusesSqlCommandBuilderorOleDbCommandBuilder,thecommandtextoftheUpdateandDeletestatementsisautomaticallyconfiguredforoptimisticconcurrency.Ifyoudonotwanttouseoptimisticconcurrency,youcanprogrammaticallymodifytheCommandTextpropertyofthedataadapter'sUpdateandDeletecommands.Formoreinformation,seeOleDbCommand.CommandTextpropertyorSqlCommand.CommandTextproperty.
Conclusion
TheSQLstatementsthatareautomaticallygeneratedbythedesigntoolsinVisualStudio.NETorbycommandbuilderobjectsusethe"checkallvalues"methodofoptimisticconcurrency.Althoughthismaynotbethemostefficientapproachforallsituations,itgeneratesaconcurrency-checkingstatementonanydatasourcethatcontainsaprimarykey.Ifyourdatausesversionnumbersortimestamps,youcanmodifythegeneratedSQLstatementsforbetterperformance.
SendfeedbackonthistopictoMicrosoft
(c)MicrosoftCorporation.Allrightsreserved.
??
??
??
??
理学院毕业论文第1页/共58页
上一篇:
ASP_net仪器设备管理系统设计与实现(论文和程序)
下一篇:
群体性突发事件论文:“边界冲突”:农村群体性事件的县域分析