1

我在 WINCC 中创建了一个项目,在其中创建表(示例在底部),然后将温度变送器的值放入其中,以一秒为周期。我的问题是,一段时间后新数据不会在表格底部出现,它会随机出现在某个位置并开始在那里写入。它不会覆盖它只是开始随机插入,然后在它进入底部并再次随机插入等等......

这是我创建表的代码:

Sub Create_new_table ()
Dim conn, rst, SQL_Table, name

On Error Resume Next

Set conn = CreateObject("ADODB.Connection")
Set rst = CreateObject("ADODB.Recordset")
name =Year(Date) & "_" & Month(Date) & "_" & Day(Date)
'Open data source - Datenquelle öffnen
conn.Open "Provider=MSDASQL;DSN=Database" 'DSN= Name of the ODBC database - DSN= Name der ODBC-Datenbank

'Error routine - Fehlerroutine
If Err.Number <> 0 Then
    ShowSystemAlarm "Error #" & Err.Number & " " & Err.Description
    Err.Clear
    Set conn = Nothing
    Exit Sub
End If


' FORMING TABLE
SQL_Table = "CREATE TABLE Paster_TT43_" & name & "(" &_
        "Signal NVARCHAR(30) ," &_
        "Date NVARCHAR(30) ," &_
        "Time NVARCHAR(30) ," &_
        "Value NVARCHAR(30)  )"
Set rst = conn.Execute(SQL_Table)

' There are more tables to create there is one for example
'Error routine - Fehlerroutine 
If Err.Number <> 0 Then
    ShowSystemAlarm "Error #" & Err.Number & " " & Err.Description
    Err.Clear
    'Close data source - Datenquelle schließen
    conn.close
    Set conn = Nothing
    Set rst = Nothing
    Exit Sub
End If

'Close data source - Datenquelle schließen
conn.close

Set rst = Nothing
Set conn = Nothing

End Sub

那是创建一个表的示例现在是向其中添加新元素的示例,它每秒都会进行一次

Sub Add_New_Element()
Dim conn, conn2, rst, SQL_Table,SQL_Table2, name, rssql, rs, insertsql, Date, Time

name =Year(Date) & "_" & Month(Date) & "_" & Day(Date)
Date = Day(Date) & "_" & Month(Date) & "_" & Year(Date) 
Time = Hour(Time) & ":" & Minute(Time) & ":" & Second(Time)

On Error Resume Next

Set conn = CreateObject("ADODB.Connection")
conn.Open "Provider=MSDASQL;Initial Catalog=BazaPodataka;DSN=Database"
If Err.Number <> 0 Then
    ShowSystemAlarm "Error #" & Err.Number & " " & Err.Description
    Err.Clear
    Set conn = Nothing
    Exit Sub
End If

SQL_Table = "INSERT INTO Paster_TT43_" & name & "(Signal, Date, Time, Value) VALUES ('" & SmartTags("15_Analog_input_TT43.Name") & "' , '" & datum & "' , ' " & vreme & "' , ' " & SmartTags("15_Analog_input_TT43.Scaled_Signal") &  " ')"
Set rst = conn.Execute(SQL_Table)

'more signals after this etc..
conn.close
Set rst = Nothing
Set conn = Nothing

End Sub

谢谢你

4

0 回答 0