回复:SQL和WINCC数据交换问题

Monsanto

  • 帖子

    142
  • 精华

    0
  • 被关注

    13

论坛等级:侠士

注册时间:2013-09-19

普通 普通 如何晋级?

发布于 2015-09-15 09:54:56

3楼

 我写了这个向数据库里添加数据,但就是不能写进去,数据库evcp中一直是空的。

还请大家赐教!

Sub savedata

Dim objConnection

Dim objCommand

Dim objRecordset

Dim strConnectionString

Dim strSQL

Dim norder,pileno,cardno,operno,energy,cost,period,rate,pdate,ptime

'变量值读取 

norder=HMIRuntime.Tags("norder").Read

pileno= HMIRuntime.Tags("pileno").Read

cardno=HMIRuntime.Tags("cardno").Read

operno= HMIRuntime.Tags("operno").Read

energy= HMIRuntime.Tags("energy").Read

cost= HMIRuntime.Tags("cost").Read

period= HMIRuntime.Tags("period").Read

rate= HMIRuntime.Tags("rate").Read

pdate= HMIRuntime.Tags("pdate").Read

ptime= HMIRuntime.Tags("ptime").Read

 ’ODBC连接数据源evcs

strConnectionString = "Provider=MSDASQL;DSN=evcs;UID=;PWD=;"

Set objConnection = CreateObject("ADODB.Connection")

objConnection.ConnectionString = strConnectionString

objConnection.Open

 

Set objRecordset = CreateObject("ADODB.Recordset")

Set objCommand = CreateObject("ADODB.Command")

objCommand.ActiveConnection = objConnection

 

strSQL = "insert into evcp (norder,pileno,cardno,operno,energy,cost,period,rate,pdate,ptime) values (  "&_

" ' "&norder&" ' ,  "&_

" ' "&pileno&" ' , "&_

" ' "&cardno&" ' , "&_

" ' "&operno&"',"&_

" ' "&energy&"',"&_

" ' "&cost&"',"&_

" ' "&period&"',"&_

" ' "&rate&"',"&_

" ' "&pdate&" ' , "&_

" ' "&ptime&" ' )"

'---MsgBox (strSQL)

objCommand.CommandText = strSQL

objCommand.Execute

 

Set objCommand = Nothing

objConnection.Close

Set objRecordset = Nothing

Set objConnection = Nothing

End Sub

西方人的思维非常人能理解透!
评论
编辑推荐: 关闭

请填写推广理由:

本版热门话题

SIMATIC S7-300/400

共有54762条技术帖

相关推荐

热门标签

相关帖子推荐

guzhang

恭喜,你发布的帖子

评为精华帖!

快扫描右侧二维码晒一晒吧!

再发帖或跟帖交流2条,就能晋升VIP啦!开启更多专属权限!

  • 分享

  • 只看
    楼主

top
X 图片
您收到0封站内信:
×
×
信息提示
很抱歉!您所访问的页面不存在,或网址发生了变化,请稍后再试。