Author Topic: Datasubscriber2 code firering twice  (Read 1299 times)

Holmux

  • Newbie
  • *
  • Posts: 34
    • View Profile
Datasubscriber2 code firering twice
« on: March 03, 2020, 02:13:54 AM »
Dear All

I need some help figuring this one out  :)

I have a Datasubscriber2 that inserts some data into a MS SQL DB, but every record is inserted twice in the DB
I have double checked the PLC code, debugged the AdvancedHMI code, they are only firering once, here is my
code:
Code: [Select]
Private Sub DataSubscriber25_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber25.DataChanged
        If e.ErrorId = 0 Then
            If e.Values(0) = True Then
                Using Con As New SqlConnection("Data Source=192.168.100.100;Initial Catalog=DB;Persist Security Info=True;User ID=Tarzan;Password=****")
                    Dim command As New SqlCommand("insert into dbo.Products(UPID, XPOS, YPOS, Error, Employee, Employee2) values(@UPID, @xpos, @ypos, @error, @employee, @employee2)", Con)
                    command.Parameters.Add("@UPID", SqlDbType.Int).Value = BasicLabel16.Value
                    command.Parameters.Add("@xpos", SqlDbType.Int).Value = BasicLabel2.Value
                    command.Parameters.Add("@ypos", SqlDbType.Int).Value = BasicLabel3.Value
                    command.Parameters.Add("@error", SqlDbType.Int).Value = BasicLabel4.Value
                    command.Parameters.Add("@employee", SqlDbType.Int).Value = BasicLabel5.Value
                    command.Parameters.Add("@employee2", SqlDbType.Int).Value = BasicLabel33.Value
                    If Con.State.ToString <> "Open" Then
                        Con.Open()
                    End If
                    command.ExecuteNonQuery()
                    If command.ExecuteNonQuery() <> 1 Then
                        Con.Close()
                        Con.Dispose()
                    End If
                End Using
                EthernetIPforCLXCom1.Write("DB_Tricker_1", 0)
            End If
        End If
    End Sub
/Holmux

Holmux

  • Newbie
  • *
  • Posts: 34
    • View Profile
Re: Datasubscriber2 code firering twice
« Reply #1 on: March 03, 2020, 10:25:08 AM »
Solved  :)

I was firering the "command.ExecuteNonQuery()" twice.

Well had been starring at the code for hours and it was right there in front of me, Sorry

/Holmux