7
« on: July 23, 2018, 03:02:46 PM »
Hi Ghodra/Phrog 30,
I am using Microsoft SQL data base(File) with table dbo.DataFile and trying to update Seq,Serial columns, with PLC addresses: Record_Seq and Record_Serial using basicdatalogger 2 when event changes (Number_Validated bit).
Using following code:
Private Value1, Value2 As String
Private Sub BasicDataLogger21_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles BasicDataLogger21.DataChanged
If e.PlcAddress = "Number_Validated" Then
BasicLabel1.Text = e.Values(0)
BasicLabel2.Text = e.Values(1)
End If
Dim con As New SqlClient.SqlConnection
Dim cmd As New SqlClient.SqlCommand
Try
con.ConnectionString = "Data Source=xxx.10.14.xxx;Initial Catalog=info;UID=sa;PWD=user"
con.Open()
cmd.Connection = con
cmd.CommandText = "INSERT INTO Test(value1,value2) VALUES(@Value1,@Value2)"
cmd.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show("Error while inserting record on table..." & ex.Message, "Insert Records")
Finally
con.Close()
End Try
I am not pretty much sure with the code and very new to VB. Can you please help me out how to record Seq,Serial data in database table when Number_Validated bit changes it state.
Thanks