现在用wincc做一个报表,wincc自带的报表编辑器没看懂杂用,现在计划使用VBS脚本把数据写入到SQL数据库中,画面中添加一个按钮动作脚本为写入数据库脚本,我ODBC也设置了DSN,测试连接成功。SQL数据库中已经建立数据库。
感觉应该是连接字符串的问题,不知道怎么修改,哪位给看一下
这个脚本连接是使用OLEDB
按钮动作脚本如下:
Sub OnClick(ByVal Item)
Dim objConnection
Dim strConnectionstring
Dim lngValue
Dim strSQL
Dim objCommand
Dim guanhao
Dim guanjing
Dim bihou
Dim caizhi
Dim SyValue
Dim MixValue
Dim MaxValue
Dim BYtime
Dim jielun
Dim CSdate
Dim CStime
Dim caozuoyuan
guanhao=HMIRuntime.Tags("管号").Read
guanjing=HMIRuntime.Tags("钢管管径").Read
bihou=HMIRuntime.Tags("壁厚").Read
caizhi=HMIRuntime.Tags("材质").Read
SyValue=HMIRuntime.Tags("试压压力设定").Read
MixValue=HMIRuntime.Tags("保压最小值").Read
MaxValue=HMIRuntime.Tags("保压最大值").Read
BYtime=HMIRuntime.Tags("保压时间").Read
jielun=HMIRuntime.Tags("试验结果").Read
CSdate=HMIRuntime.Tags("试验日期").Read
CStime=HMIRuntime.Tags("试验时间").Read
caozuoyuan=HMIRuntime.Tags("操作员").Read
strConnectionstring = "Provider=SQLOLEDB.1;Password=123456;User ID=sa;Data Source=local"
'strSQL="insert into report values ("'&guanhao&'","'&guanjing&'","'&bihou&'","'&caizhi&'","'&SyValue&'","'&MixValue&'","'&MaxValue&'","'&BYtime&'","'&jielun&'","'&CSdate&'","'&CStime&'","'&caozuoyuan&'")"
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Connectionstring = strConnectionstring
objConnection.open
Set objCommand = CreateObject("ADODB.Command")
With objCommand
.ActiveConnection = objConnection
.CommandText = strSQL
End With
objCommand.Execute
Set objCommand = Nothing
objConnection.Close
Set objConnection = Nothing
MsgBox("cccccccccccc")
End Sub