Option Explicit Function action Dim DB,objRecordSet Dim Excel 'SQL Server服务器地址 Dim SQLserver 'SQL Server 数据库 Dim Database 'SQL Server登录名 Dim uid 'SQL Server登陆密码 Dim pwd 'SQL Server 数据库表名 Dim Tablename 'SQL Server数据库表列字段 Dim Column 'Excel表路劲 Dim XLSPath SQLserver = "WIN-B6MC1MBR5J8\WINCC" Database = "test1" uid = "sa1" pwd = "123" tablename = "testtable" Set DB = CreateObject("ADODB.Connection") Set objRecordSet = CreateObject("ADODB.RECORDSET") Set Excel = CreateObject("Excel.Application") DB.Open "Driver=SQL Server;server="&SQLserver&";Database="&Database&";uid="&uid&";pwd="&pwd&";" Dim riqi riqi=HMIRuntime.Tags("riqi") Dim shijian riqi=HMIRuntime.Tags("时间") Dim tag0 riqi=HMIRuntime.Tags("L") Dim tag1 riqi=HMIRuntime.Tags("P") Dim tag2 riqi=HMIRuntime.Tags("T") sql = "insert into "&Tablename &" VALUES ('"&riqi&"','"&shijian&"','"&tag0&"','"&tag1&"','"&tag2&"')" DB.Execute(sql) End Function