Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I'm confused and don't know how to go about this.

Here is the scenario.

I have data coming in on a serial port. "Fields(x)" is the data array from the serial port.

If the record does not exist
1.Create it
2.Add data to Fields
3.Save it to the database, and make sure it is the current record in the bindingsource, because the PK, RunID, is an autoincrament field and need that number for child table.

If it DOES Exist, meaning the record was written to the database, and it is the current record in the bindingsource. and it is the record I'm looking for then
1.Change the Description field from data coming from the serial port
2.Update it, and save it back to database.

If it not the record I'm looking for
1.load it from the database, back to the binding source, update it and save it back to database.

When I run code I get concurrency error. In VB.NET 2010 using MSSQLCE, I cannot change the Use concurreny option. It is disabled.

Code:

VB
Public Sub RunInformation1()

       'Dim recordState As Integer = frmMain.TblRunInformationTableAdapter.DoesRecordExist(Today.Date, Fields(1))
       'If the run record does not exist in DB
       If TblRunInformationTableAdapter.DoesRecordExist(Today.Date, Fields(1)) = 0 Then
           bsRunInformation.AddNew()
           bsRunInformation.Current("UniqueNumber") = Fields(1)
           bsRunInformation.Current("TDStamp") = Now
           bsRunInformation.Current("Description") = StripString(Fields(2))

       ElseIf TblRunInformationTableAdapter.DoesRecordExist(Today.Date, Fields(1)) = 1 Then
           Dim tempDate As New Date
           Try
               If Not IsDBNull(bsRunInformation.Current("TDStamp")) Then
                   tempDate = CDate(bsRunInformation.Current("TDStamp")).Date
               End If
           Catch ex As NullReferenceException

           End Try
           If tempDate = Today And bsRunInformation.Current("UniqueNumber") = Fields(1) Then
               'Try
               bsRunInformation.Current("Description") = StripString(Fields(2))
               TblRunInformationTableAdapter.UpdateSingleRow(StripString(Fields(2)), bsRunInformation.Current("RunID"))
               TblRunInformationTableAdapter.Update(DsSkySkor1.tblRunInformation)
               'Catch ex As DBConcurrencyException

               'End Try
           Else
               TblRunInformationTableAdapter.FillSingleRow(DsSkySkor1.tblRunInformation, Today, Fields(1))
               bsRunInformation.Current("Description") = StripString(Fields(2))
           End If

       End If
       bsRunInformation.EndEdit()
       TblRunInformationTableAdapter.Update(DsSkySkor1.tblRunInformation)
       Fields = Nothing
   End Sub
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900