1,105,423 Community Members

Concurrency Violation: Updatecommand update 0 on 1 expected

radeon09
Newbie Poster
2 posts since Feb 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 

Can Anyone help me in this problem?? plssss... concurrency violation

radeon09
Newbie Poster
2 posts since Feb 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 
If state = Form_State.Edit_RecordState Then
            KeyPreview = True

            Me.BSave.Text = "Update:"
            Me.SaveToolStripMenuItem.Text = "Update:"
            Me.Text = "Edit Record:"

            Try
                With cnn
                    If .State <> ConnectionState.Open Then
                        .ConnectionString = strconnection()
                        .Open()

                        With conn
                            .SelectCommand = New OleDbCommand()
                            .SelectCommand.CommandText = "SELECT * FROM [Student] WHERE (StudentID = @StudentID)"
                            .SelectCommand.Parameters.Add("@StudentID", OleDbType.VarChar, 50, "StudentID").Value = ShowBind.ToString()
                            .SelectCommand.Connection = cnn
                        End With


                        'If Modify or Edit record...Update
                        'Systax on how to update without using Commandbuilder...
                        With conn
                            .UpdateCommand = New OleDbCommand()
                            .UpdateCommand.CommandText = "UPDATE [Student] SET [FirstName] = @FirstName , [MiddleName] = @MiddleName , [LastName] = @LastName , [Age] = @Age , " & _
                            "[Nationality] = @Nationality , [CivilStatus] = @CivilStatus , [Religion] = @Religion , [Gender] = @Gender , [BirthDay] = @BirthDay , [Course] = @Course , " & _
                            "[YearandSection] = @YearandSection , [Semester] = @Semester , [SchoolYear] = @SchoolYear , [RegistrationDate] = @RegistrationDate , " & _
                            "[PrimarySchool] = @PrimarySchool , [YearGraduated] = @YearGraduated , [IntermediateSchool] = @IntermediateSchool , " & _
                            "[YearGraduated1] = @YearGraduated1 , [SecondarySchool] = @SecondarySchool , [YearGraduated2] = @YearGraduated2 , [College] = @College , [YearGraduatedC] = @YearGraduatedC , [FathersName] = @FathersName , " & _
                            "[FathersOccupation] = @FathersOccupation , [MothersName] = @MothersName , [MothersOccupation] = @MothersOccupation , [ParentAddress] = @ParentAddress , [ParentGuardian] = @ParentGuardian , [GAddress] = @GAddress ,  [LandlordName] = @LandlordName , " & _
                            "[LAddress] = @LAddress , [Scholarship] = @Scholarship , [Subject1] = @Subject1 , [Subject2] = @Subject2 , [Subject3] = @Subject3 , [Subject4] = @Subject4 , " & _
                            "[Subject5] = @Subject5 , [Subject6] = @Subject6 , [Subject7] = @Subject7 , [Subject8] = @Subject8 , [Subject9] = @Subject9 , [TuitionFee] = @TuitionFee , [Matriculation] = @Matriculation , " & _
                            "[EntranceFee] = @EntranceFee , [Athletics] = @Athletics , [CollegeDevtFund] = @CollegeDevtFund , [MedDentalFee] = @MedDentalFee , [SSGFee] = @SSGFee , [LibraryFee] = @LibraryFee , [VLPFee] = @VLPFee , [IdentificationCard] = @IdentificationCard , " & _
                            "[CollegePublication] = @CollegePublication , [MiscellaneousFee] = @MiscellaneousFee , [NSTP] = @NSTP , [TestingFee] = @TestingFee , [CulturalFee] = @CulturalFee , [StudentInsuranceFee] = @StudentInsuranceFee , [SCUAA] = @SCUAA , [NationalSCUAA] = @NationalSCUAA , " & _
                            "[GuidanceFee] = @GuidanceFee , [CulturalCHED] = @CulturalCHED , [ResearchFee] = @ResearchFee , [ExtentionFee] = @ExtentionFee , [StudentAffairsFee] = @StudentAffairsFee , [DrumandBugleCorpsFee] = @DrumandBugleCorpsFee , [HandBook] = @Handbook , [LaboratoryFee] = @LaboratoryFee , " & _
                            "[ITFee] = @ITFee , [InternetFee] = @InternetFee , [PhysicsFee] = @PhysicsFee , [BiologyFee] = @BiologyFee , [ChemistryFee] = @ChemistryFee , [SpeechFee] = @SpeechFee , [OJTFee] = @OJTFee , [Others] = @Others , [Photo] = @Photo WHERE ([StudentID] = @StudentID_Syntax)"

                            .UpdateCommand.Connection = cnn
                            .UpdateCommand.Parameters.Add("@StudentID", OleDbType.VarWChar, 50, "StudentID")
                            .UpdateCommand.Parameters.Add("@FirstName", OleDbType.VarWChar, 50, "FirstName")
                            .UpdateCommand.Parameters.Add("@MiddleName", OleDbType.VarWChar, 50, "MiddleName")
                            .UpdateCommand.Parameters.Add("@LastName", OleDbType.VarWChar, 50, "LastName")
                            .UpdateCommand.Parameters.Add("@Age", OleDbType.VarWChar, 50, "Age")
                            .UpdateCommand.Parameters.Add("@Nationality", OleDbType.VarWChar, 50, "Nationality")
                            .UpdateCommand.Parameters.Add("@CivilStatus", OleDbType.VarWChar, 50, "CivilStatus")
                            .UpdateCommand.Parameters.Add("@Religion", OleDbType.VarWChar, 50, "Religion")
                            .UpdateCommand.Parameters.Add("@Gender", OleDbType.VarWChar, 50, "Gender")
                            .UpdateCommand.Parameters.Add("@BirthDay", OleDbType.VarWChar, 50, "BirthDay")
                            .UpdateCommand.Parameters.Add("@Course", OleDbType.VarWChar, 50, "Course")
                            .UpdateCommand.Parameters.Add("@YearandSection", OleDbType.VarWChar, 50, "YearandSection")
                            .UpdateCommand.Parameters.Add("@Semester", OleDbType.VarWChar, 50, "Semester")
                            .UpdateCommand.Parameters.Add("@SchoolYear", OleDbType.VarWChar, 50, "SchoolYear")
                            .UpdateCommand.Parameters.Add("@RegistrationDate", OleDbType.VarWChar, 50, "RegistrationDate")
                            .UpdateCommand.Parameters.Add("@PrimarySchool", OleDbType.VarWChar, 50, "PrimarySchool")
                            .UpdateCommand.Parameters.Add("@YearGraduated", OleDbType.VarWChar, 50, "YearGraduated")
                            .UpdateCommand.Parameters.Add("@IntermediateSchool", OleDbType.VarWChar, 50, "IntermediateSchool")
                            .UpdateCommand.Parameters.Add("@YearGraduated1", OleDbType.VarWChar, 50, "YearGraduated1")
                            .UpdateCommand.Parameters.Add("@SecondarySchool", OleDbType.VarWChar, 50, "SecondarySchool")
                            .UpdateCommand.Parameters.Add("@YearGraduated2", OleDbType.VarWChar, 50, "YearGraduated2")
                            .UpdateCommand.Parameters.Add("@College", OleDbType.VarWChar, 50, "College")
                            .UpdateCommand.Parameters.Add("@YearGraduatedC", OleDbType.VarWChar, 50, "YearGraduatedC")
                            .UpdateCommand.Parameters.Add("@FathersName", OleDbType.VarWChar, 50, "FathersName")
                            .UpdateCommand.Parameters.Add("@FathersOccupation", OleDbType.VarWChar, 50, "FathersOccupation")
                            .UpdateCommand.Parameters.Add("@MothersName", OleDbType.VarWChar, 50, "MothersName")
                            .UpdateCommand.Parameters.Add("@MothersOccupation", OleDbType.VarWChar, 50, "MothersOccupation")
                            .UpdateCommand.Parameters.Add("@ParentAddress", OleDbType.VarWChar, 50, "ParentAddress")
                            .UpdateCommand.Parameters.Add("@ParentGuardian", OleDbType.VarWChar, 50, "ParentGuardian")
                            .UpdateCommand.Parameters.Add("@GAddress", OleDbType.VarWChar, 50, "GAddress")
                            .UpdateCommand.Parameters.Add("@LandlordName", OleDbType.VarWChar, 50, "LandlordName")
                            .UpdateCommand.Parameters.Add("@LAddress", OleDbType.VarWChar, 50, "LAddress")
                            .UpdateCommand.Parameters.Add("@Scholarship", OleDbType.VarWChar, 50, "Scholarship")
                            .UpdateCommand.Parameters.Add("@Photo", OleDbType.Binary, 0, "Photo")
                            .UpdateCommand.Parameters.Add("@Subject1", OleDbType.VarWChar, 50, "Subject1")
                            .UpdateCommand.Parameters.Add("@Subject2", OleDbType.VarWChar, 50, "Subject2")
                            .UpdateCommand.Parameters.Add("@Subject3", OleDbType.VarWChar, 50, "Subject3")
                            .UpdateCommand.Parameters.Add("@Subject4", OleDbType.VarWChar, 50, "Subject4")
                            .UpdateCommand.Parameters.Add("@Subject5", OleDbType.VarWChar, 50, "Subject5")
                            .UpdateCommand.Parameters.Add("@Subject6", OleDbType.VarWChar, 50, "Subject6")
                            .UpdateCommand.Parameters.Add("@Subject7", OleDbType.VarWChar, 50, "Subject7")
                            .UpdateCommand.Parameters.Add("@Subject8", OleDbType.VarWChar, 50, "Subject8")
                            .UpdateCommand.Parameters.Add("@Subject9", OleDbType.VarWChar, 50, "Subject9")
                            .UpdateCommand.Parameters.Add("@TuitionFee", OleDbType.VarWChar, 50, "TuitionFee")
                            .UpdateCommand.Parameters.Add("@Matriculation", OleDbType.VarWChar, 50, "Matriculation")
                            .UpdateCommand.Parameters.Add("@EntranceFee", OleDbType.VarWChar, 50, "EntranceFee")
                            .UpdateCommand.Parameters.Add("@Athletics", OleDbType.VarWChar, 50, "Athletics")
                            .UpdateCommand.Parameters.Add("@CollegeDevtFund", OleDbType.VarWChar, 50, "CollegeDevtFund")
                            .UpdateCommand.Parameters.Add("@MedDentalFee", OleDbType.VarWChar, 50, "MedDentalFee")
                            .UpdateCommand.Parameters.Add("@SSGFee", OleDbType.VarWChar, 50, "SSGFee")
                            .UpdateCommand.Parameters.Add("@LibraryFee", OleDbType.VarWChar, 50, "LibraryFee")
                            .UpdateCommand.Parameters.Add("@VLPFee", OleDbType.VarWChar, 50, "VLPFee")
                            .UpdateCommand.Parameters.Add("@IdentificationCard", OleDbType.VarWChar, 50, "IdentificationCard")
                            .UpdateCommand.Parameters.Add("@CollegePublication", OleDbType.VarWChar, 50, "CollegePublication")
                            .UpdateCommand.Parameters.Add("@MiscellaneousFee", OleDbType.VarWChar, 50, "MiscellaneousFee")
                            .UpdateCommand.Parameters.Add("@NSTP", OleDbType.VarWChar, 50, "NSTP")
                            .UpdateCommand.Parameters.Add("@TestingFee", OleDbType.VarWChar, 50, "TestingFee")
                            .UpdateCommand.Parameters.Add("@CulturalFee", OleDbType.VarWChar, 50, "CulturalFee")
                            .UpdateCommand.Parameters.Add("@StudentInsuranceFee", OleDbType.VarWChar, 50, "StudentInsuranceFee")
                            .UpdateCommand.Parameters.Add("@SCUAA", OleDbType.VarWChar, 50, "SCUAA")
                            .UpdateCommand.Parameters.Add("@NationalSCUAA", OleDbType.VarWChar, 50, "NationalSCUAA")
                            .UpdateCommand.Parameters.Add("@GuidanceFee", OleDbType.VarWChar, 50, "GuidanceFee")
                            .UpdateCommand.Parameters.Add("@CulturalCHED", OleDbType.VarWChar, 50, "CulturalCHED")
                            .UpdateCommand.Parameters.Add("@ResearchFee", OleDbType.VarWChar, 50, "ResearchFee")
                            .UpdateCommand.Parameters.Add("@ExtentionFee", OleDbType.VarWChar, 50, "ExtentionFee")
                            .UpdateCommand.Parameters.Add("@StudentAffairsFee", OleDbType.VarWChar, 50, "StudentAffairsFee")
                            .UpdateCommand.Parameters.Add("@DrumandBugleCorpsFee", OleDbType.VarWChar, 50, "DrumandBugleCorpsFee")
                            .UpdateCommand.Parameters.Add("@HandBook", OleDbType.VarWChar, 50, "HandBook")
                            .UpdateCommand.Parameters.Add("@LaboratoryFee", OleDbType.VarWChar, 50, "LaboratoryFee")
                            .UpdateCommand.Parameters.Add("@ITFee", OleDbType.VarWChar, 50, "ITFee")
                            .UpdateCommand.Parameters.Add("@InternetFee", OleDbType.VarWChar, 50, "InternetFee")
                            .UpdateCommand.Parameters.Add("@PhysicsFee", OleDbType.VarWChar, 50, "PhysicsFee")
                            .UpdateCommand.Parameters.Add("@BiologyFee", OleDbType.VarWChar, 50, "BiologyFee")
                            .UpdateCommand.Parameters.Add("@ChemistryFee", OleDbType.VarWChar, 50, "ChemistryFee")
                            .UpdateCommand.Parameters.Add("@SpeechFee", OleDbType.VarWChar, 50, "SpeechFee")
                            .UpdateCommand.Parameters.Add("@OJTFee", OleDbType.VarWChar, 50, "OJTFee")
                            .UpdateCommand.Parameters.Add("@Others", OleDbType.VarWChar, 50, "Others")

                            'To handle error like (Concurrency violation: The UpdateCommand affected 0 of the expected 1 records...)
                            'DataRow Version Original...
                            .UpdateCommand.Parameters.Add(New System.Data.OleDb.OleDbParameter("@StudentID_Syntax", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "StudentID", DataRowVersion.Original, True))
                            '.UpdateCommand.Parameters.Add(New System.Data.OleDb.OleDbParameter("@Photo", System.Data.OleDb.OleDbType.Binary, 0, System.Data.ParameterDirection.Input, False, CType(0, Long), CType(0, Long), "Photo", DataRowVersion.Original, True))

                            '.UpdateCommand.Parameters.Add(New System.Data.OleDb.OleDbParameter("@StudentID_Syntax", System.Data.OleDb.OleDbType.VarWChar, 50, _
                            'System.Data.ParameterDirection.Input, False, _
                            ' CType(0, Byte), CType(0, Byte), "StudentID", _
                                                            ' DataRowVersion.Original, True))
                        End With

                        setdata2.Clear()
                        conn.Fill(setdata2, "Student")
                        Me.txtstudentid.DataBindings.Add(New Binding("Text", setdata2, "Student.StudentID", True))
                        Me.txtfirstname.DataBindings.Add(New Binding("Text", setdata2, "Student.FirstName", True))
                        Me.txtmiddlename.DataBindings.Add(New Binding("Text", setdata2, "Student.MiddleName", True))
                        Me.txtlastname.DataBindings.Add(New Binding("Text", setdata2, "Student.LastName", True))
                        Me.txtage.DataBindings.Add(New Binding("Text", setdata2, "Student.Age", True))
                        Me.txtnationality.DataBindings.Add(New Binding("Text", setdata2, "Student.Nationality", True))
                        Me.cmbstatus.DataBindings.Add(New Binding("Text", setdata2, "Student.CivilStatus", True))
                        Me.txtreligion.DataBindings.Add(New Binding("Text", setdata2, "Student.Religion", True))
                        Me.cmbgender.DataBindings.Add(New Binding("Text", setdata2, "Student.Gender", True))
                        Me.dtpbday.DataBindings.Add(New Binding("Text", setdata2, "Student.BirthDay", True))
                        Me.cmbcourse.DataBindings.Add(New Binding("Text", setdata2, "Student.Course", True))
                        Me.cmbyearandsection.DataBindings.Add(New Binding("Text", setdata2, "Student.YearandSection", True))
                        Me.cmbsem.DataBindings.Add(New Binding("Text", setdata2, "Student.Semester", True))
                        Me.txtschoolyear.DataBindings.Add(New Binding("Text", setdata2, "Student.SchoolYear", True))
                        Me.txtscholarship.DataBindings.Add(New Binding("Text", setdata2, "Student.Scholarship", True))
                        Me.dtpregistration.DataBindings.Add(New Binding("Text", setdata2, "Student.RegistrationDate", True))

                        Me.txtelem.DataBindings.Add(New Binding("Text", setdata2, "Student.PrimarySchool", True))
                        Me.txtyearelem.DataBindings.Add(New Binding("Text", setdata2, "Student.YearGraduated", True))
                        Me.txtintermediate.DataBindings.Add(New Binding("Text", setdata2, "Student.IntermediateSchool", True))
                        Me.txtyearintermediate.DataBindings.Add(New Binding("Text", setdata2, "Student.YearGraduated1", True))
                        Me.txthighschool.DataBindings.Add(New Binding("Text", setdata2, "Student.SecondarySchool", True))
                        Me.txtyearhighschool.DataBindings.Add(New Binding("Text", setdata2, "Student.YearGraduated2", True))
                        Me.txtcollege.DataBindings.Add(New Binding("Text", setdata2, "Student.College", True))
                        Me.txtyearcollege.DataBindings.Add(New Binding("Text", setdata2, "Student.YearGraduatedC", True))
                        Me.txtfather.DataBindings.Add(New Binding("Text", setdata2, "Student.FathersName", True))
                        Me.txtfather1.DataBindings.Add(New Binding("Text", setdata2, "Student.FathersOccupation", True))
                        Me.txtmother.DataBindings.Add(New Binding("Text", setdata2, "Student.MothersName", True))
                        Me.txtmother1.DataBindings.Add(New Binding("Text", setdata2, "Student.MothersOccupation", True))
                        Me.txtparentadd.DataBindings.Add(New Binding("Text", setdata2, "Student.ParentAddress", True))
                        Me.txtguardian.DataBindings.Add(New Binding("Text", setdata2, "Student.ParentGuardian", True))
                        Me.txtguardianadd.DataBindings.Add(New Binding("Text", setdata2, "Student.GAddress", True))
                        Me.txtlandlady.DataBindings.Add(New Binding("Text", setdata2, "Student.LandlordName", True))
                        Me.txtlandladyadd.DataBindings.Add(New Binding("Text", setdata2, "Student.LAddress", True))
                        Me.txtsubject1.DataBindings.Add(New Binding("Text", setdata2, "Student.Subject1", True))
                        Me.txtsubject2.DataBindings.Add(New Binding("Text", setdata2, "Student.Subject2", True))
                        Me.txtsubject3.DataBindings.Add(New Binding("Text", setdata2, "Student.Subject3", True))
                        Me.txtsubject4.DataBindings.Add(New Binding("Text", setdata2, "Student.Subject4", True))
                        Me.txtsubject5.DataBindings.Add(New Binding("Text", setdata2, "Student.Subject5", True))
                        Me.txtsubject6.DataBindings.Add(New Binding("Text", setdata2, "Student.Subject6", True))
                        Me.txtsubject7.DataBindings.Add(New Binding("Text", setdata2, "Student.Subject7", True))
                        Me.txtsubject8.DataBindings.Add(New Binding("Text", setdata2, "Student.Subject8", True))
                        Me.txtsubject9.DataBindings.Add(New Binding("Text", setdata2, "Student.Subject9", True))
                        Me.txttuition.DataBindings.Add(New Binding("Text", setdata2, "Student.TuitionFee", True))
                        Me.txtmatriculation.DataBindings.Add(New Binding("Text", setdata2, "Student.Matriculation", True))
                        Me.txtentrance.DataBindings.Add(New Binding("Text", setdata2, "Student.EntranceFee", True))
                        Me.txtathletics.DataBindings.Add(New Binding("Text", setdata2, "Student.Athletics", True))
                        Me.txtcollegedvt.DataBindings.Add(New Binding("Text", setdata2, "Student.CollegeDevtFund", True))
                        Me.txtmeddental.DataBindings.Add(New Binding("Text", setdata2, "Student.MedDentalFee", True))
                        Me.txtssg.DataBindings.Add(New Binding("Text", setdata2, "Student.SSGFee", True))
                        Me.txtlibrary.DataBindings.Add(New Binding("Text", setdata2, "Student.LibraryFee", True))
                        Me.txtvlp.DataBindings.Add(New Binding("Text", setdata2, "Student.VLPFee", True))
                        Me.txtid.DataBindings.Add(New Binding("Text", setdata2, "Student.IdentificationCard", True))
                        Me.txtpublication.DataBindings.Add(New Binding("Text", setdata2, "Student.CollegePublication", True))
                        Me.txtmisc.DataBindings.Add(New Binding("Text", setdata2, "Student.MiscellaneousFee", True))
                        Me.txtnstp.DataBindings.Add(New Binding("Text", setdata2, "Student.NSTP", True))
                        Me.txttesting.DataBindings.Add(New Binding("Text", setdata2, "Student.TestingFee", True))
                        Me.txtcultural.DataBindings.Add(New Binding("Text", setdata2, "Student.CulturalFee", True))
                        Me.txtinsurance.DataBindings.Add(New Binding("Text", setdata2, "Student.StudentInsuranceFee", True))
                        Me.txtscuaa.DataBindings.Add(New Binding("Text", setdata2, "Student.SCUAA", True))
                        Me.txtnscuaa.DataBindings.Add(New Binding("Text", setdata2, "Student.NationalSCUAA", True))
                        Me.txtguidance.DataBindings.Add(New Binding("Text", setdata2, "Student.GuidanceFee", True))
                        Me.txtculturalched.DataBindings.Add(New Binding("Text", setdata2, "Student.CulturalCHED", True))
                        Me.txtresearch.DataBindings.Add(New Binding("Text", setdata2, "Student.ResearchFee", True))
                        Me.txtextention.DataBindings.Add(New Binding("Text", setdata2, "Student.ExtentionFee", True))
                        Me.txtstudentaffairs.DataBindings.Add(New Binding("Text", setdata2, "Student.StudentAffairsFee", True))
                        Me.txtdrum.DataBindings.Add(New Binding("Text", setdata2, "Student.DrumandBugleCorpsFee", True))
                        Me.txthandbook.DataBindings.Add(New Binding("Text", setdata2, "Student.HandBook", True))
                        Me.txtlab.DataBindings.Add(New Binding("Text", setdata2, "Student.LaboratoryFee", True))
                        Me.txtit.DataBindings.Add(New Binding("Text", setdata2, "Student.ITFee", True))
                        Me.txtinternet.DataBindings.Add(New Binding("Text", setdata2, "Student.InternetFee", True))
                        Me.txtphysics.DataBindings.Add(New Binding("Text", setdata2, "Student.PhysicsFee", True))
                        Me.txtbiology.DataBindings.Add(New Binding("Text", setdata2, "Student.BiologyFee", True))
                        Me.txtchem.DataBindings.Add(New Binding("Text", setdata2, "Student.ChemistryFee", True))
                        Me.txtspeech.DataBindings.Add(New Binding("Text", setdata2, "Student.SpeechFee", True))
                        Me.txtojt.DataBindings.Add(New Binding("Text", setdata2, "Student.OJTFee", True))
                        Me.txtothers.DataBindings.Add(New Binding("Text", setdata2, "Student.Others", True))
                        main = FrmListofStudent
                        Me.PicStudent.Image = FrmListofStudent.PictureBox1.Image

                    End If
                End With
            Catch ex As Exception
                MsgBox(ex.Message(), MsgBoxStyle.Critical, "Error!!!")
            Finally
                cnn.Close()

            End Try
            Exit Sub
        End If
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article