Dim conn1,oCom1,oRs1,oCom2,oRs2,oCom3,oRs3,objConn
Dim con,rq,num,sj,hu,num2
Dim a,b,c,d,datetime,e
Set a=HMIRuntime.Tags("Name1")
Set c=HMIRuntime.Tags("flow100")
Set datetime=HMIRuntime.Tags("TIME")
a.Read
c.Read
datetime.Read
datetime.Value=Now
datetime.Write
d=datetime.Value
Msgbox d
dim strsql
strsql="INSERT INTO Table2([Value]) VALUES(" & c.Value & ")"'添加一行,与原表格对应
Msgbox strsql
Set conn1=Createobject("ADODB.Connection")
con = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=123456;Intial Catalog=test;Data Source=.WINCC;"
'con = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Intial Catalog=wincctest;Data Source=XCGDQ02WINCC;"'本地数据库,使用windows身份验证登录
'Provider指定驱动程序,Integrated Security=SSPI代表windows身份验证登录SQL SERVER,Persist Security Info是否保存登录信息,默认不保存,Intial Catalog要访问的数据库名称,Data Source数据库地址
'con = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=123456;Intial Catalog=wincctest;Data Source=IP,1433"'远程数据库,使用SQL SERVER账户验证登录数据源选择时填写远程的IP地址以及“,1433”1433是端口号,需要在远程服务器上进行配置
conn1.ConnectionString=con
conn1.CursorLocation = 3
'打开数据库连接
conn1.Open
'创建记录集
Set oRs1=Createobject("ADODB.Recordset")
Set oCom1=Createobject("ADODB.Command")
oCom1.CommandType=1
With oCom1
.ActiveConnection = conn1
.CommandText = strsql
End With
Msgbox "即将写入"
Set oRs1=oCom1.Execute
a.Write
c.Write
Msgbox "写入成功"
oRs1.Close
Set oRs1=Nothing
Set oCom1=Nothing
conn1.Close
Set conn1=Nothing
err.clear()
执行上面的脚本报错

下面是数据库表格截图
