I am using Datasubsciber2 to monitor 3 tags from a plc, I then write them three values to a SQLite db with accompanied buy a timestamp column. However when I check the db, instead of writing all three values into the same row it generates a new row for each value. Any clue on how I get it to write all the data required to a single row, have I made an error in my code? See attached a screenshot of the db.
Dim tstamp As String = DateAndTime.Now
Dim hrnow As Integer = DateAndTime.Now.TimeOfDay.Hours
Dim p1speed As String
Dim p1amps As Integer
Dim p1temp As Integer
If Not System.IO.File.Exists(fullname) Then
Dim ct As String = "CREATE TABLE Trends (tstamp Text,p1speed Integer,p1amps Integer, p1temp Integer);"
Using sqlconn As New SQLite.SQLiteConnection(cs)
Dim cmd As New SQLiteCommand(ct, sqlconn)
sqlconn.Open()
cmd.ExecuteNonQuery()
End Using
End If
If e.PlcAddress = "400201" Then
p1speed = e.Values(0)
End If
If e.PlcAddress = "400202" Then
p1amps = e.Values(0)
End If
If e.PlcAddress = "400103" Then
p1temp = CInt(e.Values(0))
End If
Dim myconnection As New SQLiteConnection(cs)
myconnection.Open()
Dim cmdd As New SQLiteCommand
cmdd.Connection = myconnection
cmdd.CommandText = "Insert into Trends (tstamp,p1speed,p1amps,p1temp) VALUES(@tstamp,@p1speed,@p1amps,@p1temp)"
cmdd.Parameters.AddWithValue("@tstamp", tstamp)
cmdd.Parameters.AddWithValue("@p1speed", p1speed)
cmdd.Parameters.AddWithValue("@p1amps", p1amps)
cmdd.Parameters.AddWithValue("@p1temp", p1temp)
cmdd.ExecuteNonQuery()
myconnection.Close()