9
Hướng dẫn lưu giá trị trên wincc vào csdl B1: mở Sql 2005 lên Sau khi mở lên chọn connect B2: tao CSDL Vào mục database chọn csdl mà bạn muốn lưu dữ liệu vào. Tạo table lưu dữ liệu

Hướng-dẫn-lưu-giá-trị-trên-wincc-vào-csdl

Embed Size (px)

DESCRIPTION

SQL

Citation preview

Hng dn lu gi tr trn wincc vo csdlB1: m Sql 2005 ln

Sau khi m ln chn connectB2: tao CSDLVo mc database chn csdl m bn mun lu d liu vo. To table lu d liu

To ct dng lu d liu vo bao gm tn ct v loi d liu cn lu

Sau khi to xong lu li vi tn bn mun

Vy l xong bc to csdl. By gi bn vo Wincc to 1 event dung lu d liu theo thi gian.

Bn c th dung C hoc VB. Mnh th dung VB

To Trigger

Mnh to trigger 10s. vy c 10s event ny s chy 1 ln v ly gi tr a vo csdl cho ban

Code trong EventOption ExplicitFunction actionDim objConnectionDim strConnectionStringDim strSQLDim objCommand

Dim mdayDim NewTag_1Dim NewTagDim TimerSet Timer = HMIRuntime.Tags("timer")

mday =FormatDateTime(Now(),0)

Timer.Write mday

strConnectionString ="Driver={SQL Native Client};Server=tiendung\wincc;Database=CC_fffff_11_07_22_12_18_23R;Trusted_Connection=yes;"

NewTag_1 = HMIRuntime.Tags("NewTag_1").ReadNewTag = HMIRuntime.Tags("NewTag").Read

strSQL = "INSERT INTO dbo.test (Date,Values1,Values2) VALUES ('"& mday & "' ,'"& NewTag & "' ,'" & NewTag_1 & "');"

Set objConnection = CreateObject("ADODB.Connection")

objConnection.ConnectionString = strConnectionString

objConnection.Open

Set objCommand = CreateObject("ADODB.Command")

With objCommand

Thnh qu

Mun c d liu ny ln bn c th dung VBS Or VB.Finish.

[email protected]