,youcanmodifythegeneratedcommandtextsoitdoesnothavetocheckeveryoriginalvalueagainstthevaluesinthedatasource.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_net010电子购物商城系统+论文(论文和程序)
下一篇:
高容量手机电池产品开发论文