Author Topic: Reading Data from SQL  (Read 3015 times)

NewControls

  • Newbie
  • *
  • Posts: 11
    • View Profile
Reading Data from SQL
« 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!

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Reading Data from SQL
« Reply #1 on: November 20, 2017, 11:20:24 AM »
How are you sending the data to the database? Are you using a table adapter?

Phrog30

  • Guest
Re: Reading Data from SQL
« Reply #2 on: November 20, 2017, 08:13:23 PM »

NewControls

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Reading Data from SQL
« Reply #3 on: November 21, 2017, 08:53:22 AM »
Yes i'm using the tableAdapter, here is a sample of what i'm doing

Code: [Select]
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

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Reading Data from SQL
« Reply #4 on: November 21, 2017, 04:39:20 PM »
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.