哪位大神给看看问题出在哪儿了?数据库用户名和密码都正确
wincc里test为32位浮点数,内部变量,以下是脚本
Sub OnClick(Byval Item)
Dim Conn
Set Conn=Createobject("ADODB.Connection")
Dim sPro, sDsn , sSer,sCon
sPro = "Provider=SQLOLEDB.1;"
sDsn = "Password=da123;PersistSecurity Info=True;"
sSer = "User ID=da;InitialCatalog=PLCdata;DataSource=Windows7-PRO-PC\WINCC"
sCon = sPro & sDsn & sSer
Conn.ConnectionString = sCon
Dim Table
Table = "test"
Dim Int1
Set Int1 = HMIRuntime.Tags("test")
Dim SqlInTo
SqlInTo = "Insert Into Table(Int1) Values(‘ "&Int1.Value&" ’) "
Conn.Execute (SqlInTo)
Conn.Close
Set Conn = Nothing
End Sub
钻石用户推荐最佳答案
此回答已完善
例程:
把wincc变量
REPORT1.NO1
REPORT1.NO2
REPORT1.NO3
。。。
写到数据库MinuteTable
var1
var2
var3
。。。
用了很多年的报表
-----------------------------------------------------------------------------
Dim Dy
Dim strSQL,strConnectionString,myDy
Dim objConnection,objCommand
Dim myMinute ,mySec
Dim v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15
Dy = Now
myMinute = Minute(Dy)
mySec = Second(Dy)
myDy = CStr(Dy)
v1=CStr(HMIRuntime.Tags("REPORT1.NO1").Read)
v2=CStr(HMIRuntime.Tags("REPORT1.NO2").Read)
v3=CStr(HMIRuntime.Tags("REPORT1.NO3").Read)
v4=CStr(HMIRuntime.Tags("REPORT1.NO4").Read)
v5=CStr(HMIRuntime.Tags("var5").Read)
v6=CStr(HMIRuntime.Tags("var6").Read)
v7=CStr(HMIRuntime.Tags("var7").Read)
v8=CStr(HMIRuntime.Tags("var8").Read)
v9=CStr(HMIRuntime.Tags("var9").Read)
v10=CStr(HMIRuntime.Tags("var10").Read)
v11=CStr(HMIRuntime.Tags("var11").Read)
v12=CStr(HMIRuntime.Tags("var12").Read)
v13=CStr(HMIRuntime.Tags("var13").Read)
v14=CStr(HMIRuntime.Tags("var14").Read)
v15=CStr(HMIRuntime.Tags("var15").Read)
strConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=CRTest;Data Source=.\WinCC;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=FF-PC;Use Encryption for Data=False;Tag with column collation when possible=False;"
strSQL = "INSERT INTO MinuteTable (Dy"
strSQL = strSQL + ",var1"
strSQL = strSQL + ",var2"
strSQL = strSQL + ",var3"
strSQL = strSQL + ",var4"
strSQL = strSQL + ",var5"
strSQL = strSQL + ",var6"
strSQL = strSQL + ",var7"
strSQL = strSQL + ",var8"
strSQL = strSQL + ",var9"
strSQL = strSQL + ",var10"
strSQL = strSQL + ",var11"
strSQL = strSQL + ",var12"
strSQL = strSQL + ",var13"
strSQL = strSQL + ",var14"
strSQL = strSQL + ",var15"
strSQL = strSQL + ") VALUES (''" + myDy + "''"
strSQL = strSQL + "," + v1
strSQL = strSQL + "," + v2
strSQL = strSQL + "," + v3
strSQL = strSQL + "," + v4
strSQL = strSQL + "," + v5
strSQL = strSQL + "," + v6
strSQL = strSQL + "," + v7
strSQL = strSQL + "," + v8
strSQL = strSQL + "," + v9
strSQL = strSQL + "," + v10
strSQL = strSQL + "," + v11
strSQL = strSQL + "," + v12
strSQL = strSQL + "," + v13
strSQL = strSQL + "," + v14
strSQL = strSQL + "," + v15
strSQL = strSQL + ")"
Set objConnection = CreateObject("ADODB.Connection")
objConnection.ConnectionString = strConnectionString
objConnection.Open
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = strSQL
objCommand.Execute
Set objCommand = Nothing
objConnection.Close
Set objConnection = Nothing
提问者对于答案的评价:
原创文章,作者:ximenziask,如若转载,请注明出处:https://www.zhaoplc.com/plc356744.html