用SQL建立一个本地数据库,然后和WINCC建立连接,然后用VB读取和修改SQL数据库里面内容,最好是实例。
1个回答
展开全部
具体操作修改一下连接字符串和sSql里的命令就可以了
Dim sCon
Dim sSql
Dim oRs
Dim conn
Dim oCom
Dim Con
Dim Data1, Data2, Data3
‘读取wincc变量
Data1=HMIRuntime.tags("编号").read
Data2=HMIRuntime.tags("姓名").read
Data3=HMIRuntime.tags("年龄").read
‘连接数据库
Con="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=读写数据库;Data Source=.\WINCC"
Set conn = CreateObject("ADODB.Connection")
conn.ConnectionString = Con
conn.CursorLocation = 3
conn.Open
‘写入数据库
sSql="insert into个人信息VALUES('" & Data1 & "','" & Data2&"','"&Data3&"');"
Set oRs = CreateObject("ADODB.Recordset")
Set oCom = CreateObject("ADODB.Command")
Set oCom.ActiveConnection = conn
oCom.CommandType = 1
oCom.CommandText = sSql
Set oRs = oCom.Execute
Set oRs = Nothing
conn.Close
Set conn = Nothing
Dim sCon
Dim sSql
Dim oRs
Dim conn
Dim oCom
Dim Con
Dim Data1, Data2, Data3
‘读取wincc变量
Data1=HMIRuntime.tags("编号").read
Data2=HMIRuntime.tags("姓名").read
Data3=HMIRuntime.tags("年龄").read
‘连接数据库
Con="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=读写数据库;Data Source=.\WINCC"
Set conn = CreateObject("ADODB.Connection")
conn.ConnectionString = Con
conn.CursorLocation = 3
conn.Open
‘写入数据库
sSql="insert into个人信息VALUES('" & Data1 & "','" & Data2&"','"&Data3&"');"
Set oRs = CreateObject("ADODB.Recordset")
Set oCom = CreateObject("ADODB.Command")
Set oCom.ActiveConnection = conn
oCom.CommandType = 1
oCom.CommandText = sSql
Set oRs = oCom.Execute
Set oRs = Nothing
conn.Close
Set conn = Nothing
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询