当前位置: 主页 > PLC控制

下面是写入数据库程序,我不太明白,能帮我解释下最后9行的意思吗?

DimsCon
DimsSql
DimoRs
Dimconn
DimoCom
DimCon
DimData1,Data2,Data3

‘读取wincc变量

Data1=HMIRuntime.tags("number").read
Data2=HMIRuntime.tags("name").read
Data3=HMIRuntime.tags("age").read

连接数据库

Con="Provider=SQLOLEDB.1;IntegratedSecurity=SSPI;PersiSTSecurityInfo=False;InitialCatalog=DUXIESHUJUKU;DatASource=.\WINCC"
Setconn=CreateObject("ADODB.Connection")

conn.ConnectionString=Con
conn.CursorLocation=3

conn.Open

‘写入数据库


sSql="inseRTintogerenxinxi1(number,name,age)VALUES(‘"&Data1&"’,’"&Data2&"’,’"&Data3&"’);"

SetoRs=CreateObject("ADODB.Recordset")

SetoCom=CreateObject("ADODB.Command")

SetoCom.ActiveConnection=conn

oCom.CommandType=1

oCom.CommandText=sSql

SetoRs=oCom.Execute

SetoRs=Nothing

conn.Close

Setconn=Nothing

最佳答案

SetoRs=CreateObject("ADODB.Recordset")‘设置数据库记录指针

SetoCom=CreateObject("ADODB.Command")’数据库操作命令

SetoCom.ActiveConnection=conn‘链接数据库

oCom.CommandType=1链接类型

oCom.CommandText=sSql链接数据库脚本

SetoRs=oCom.Execute执行数据库链接

SetoRs=Nothing释放指针

conn.Close关闭数据库

Setconn=Nothing’释放数据库链接句柄

提问者对于答案的评价:
谢谢你回答我的问题,可以给我点资料吗?我的qq:869191338
下面是我遇到的有一个问题

我在name变量中输入汉字例如“张”数据库中显示的是“?”,输入“zhang”数据库中可以显示“zhang”不知道怎么回事啊?

最佳答案作者回复:
这应该是你的系统问题,你试试手动向数据库中写入“张”看看。

  • 关注微信

猜你喜欢

微信公众号