问 wincc 如何将变量(s7300和内部变量)通过按钮写入数据库,并可以通过另外一个按钮对时间范围内保存的数据进行读写,打印
最佳答案
自己建立一个数据库就可以了,以下脚本是在dbuser下建立的表格table1中插入数据,仅供参考:
Dim cnn As String
cnn = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=dbuser;Data Source=ComputerName\wincc"
Set cc1 = CreateObject("adodb.connection")
cc1.ConnectionString = cnn
cc1.CursorLocation = 3
cc1.Open
Dim rst As Object
Set rst = CreateObject("adodb.recordset")
Dim ssql As String
ssql = "insert into table1 values(''''登入时间'''',''''登录用户名'''',''''登录其它信息'''')"
cc1.Close
Set cc1 = Nothing
Set rst = Nothing
查询的话把ssql语句改成select格式,至于你查询出来要怎么处理就看你的了,网上也很多这样的例子。给你一个查询归档数据到excel表格的例子,供参考:
Dim cnn As String
cnn = "provider=WinCCOLEDBProvider.1;catalog=CC_gz_food_09_07_14_14_54_22R;data source=wincc01\WinCC"
dim cc1 as object
Set cc1 = CreateObject("adodb.connection")
cc1.ConnectionString = cnn
cc1.CursorLocation = 3
cc1.Open
Dim rst As Object
Set rst = CreateObject("adodb.recordset")
Dim fname
fname="e:\baobiao\report.xls"
Dim ObjExcelApp
Set objExcelApp = CreateObject("Excel.Application")
objExcelApp.Workbooks.Open fname
Dim i
i=4
Dim ssql As String
ssql = "TAG:R,''speed1\c_speed1_1'',''2009-09-24 09:19:00.000'',''2009-09-24 09:20:00.000''"
rst.Open ssql, cc1
rst.MoveFirst
objExcelApp.worksheets ("sheet1").Cells(i, 2).VAlue = rst.fields(1).value
objExcelApp.worksheets ("sheet1").Cells(i, 3).VAlue = rst.fields(2).value
objExcelApp.worksheets ("sheet1").Cells(i, 4).VAlue = rst.fields(3).value
cc1.Close
objEXcelApp.ActiveWorkbook.Save
objEXcelApp.workbooks.close
objExcelApp.Quit
Set cc1 = Nothing
Set rst = Nothing
Set objExcelApp = Nothing
提问者对于答案的评价:
thanky
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc221018.html