AdvancedHMI Software
General Category => Open Discussion => Topic started by: NewControls on November 20, 2017, 10:43:33 AM
-
Guys,
Now that I have been having great success using DataSubscribers, i would like to see if there is an easy way to check what info is in the latest row of the database. Or what is the best way for me to make sure that the data i sent to the Database did indeed make it there.
Thanks!
-
How are you sending the data to the database? Are you using a table adapter?
-
There is a ton of help in SQL queries, here's one,
https://stackoverflow.com/questions/5191503/how-to-select-the-last-record-of-a-table-in-sql (https://stackoverflow.com/questions/5191503/how-to-select-the-last-record-of-a-table-in-sql)
-
Yes i'm using the tableAdapter, here is a sample of what i'm doing
Private Sub DataSubscriber9_Datareturned(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber9.DataReturned
If t.Count = 0 Then
t.AddGE_Test_DataRow(t.NewRow)
End If
t(0).LeakDecayData = e.Values(0)
If Not t(0).Is_DateNull And Not t(0).IsTimeNull And Not t(0).IsBarcodeNull And Not t(0).Is_Cavity_Null And Not t(0).Is_TestCell_Null And Not t(0).IsTestHeadNull And Not t(0).IsTestResultNull And Not t(0).IsPressurePortDataNull And Not t(0).IsLeakDecayDataNull And Not t(0).Barcode = "999" Then
Using ta As New ControlsDBGETubTableAdapters.GE_Test_DataTableAdapter
ta.Update(t)
t.Clear()
End Using
End If
End Sub
Thanks
-
If the data doesn't make it to the database, the Update will throw an exception.
If you want to double make sure, one trick is to create an Identity Specification column in which the SQL server will automatically create a unique number. In the table you have in your VB code, that column will be set to a negative number after adding the row. Once the update succeeds, the negative number will be replaced by the actual number the server generated. So you can check to see if the number if >= 0 after the update.