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:
Public Sub RunInformation1()
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
bsRunInformation.Current("Description") = StripString(Fields(2))
TblRunInformationTableAdapter.UpdateSingleRow(StripString(Fields(2)), bsRunInformation.Current("RunID"))
TblRunInformationTableAdapter.Update(DsSkySkor1.tblRunInformation)
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