写了个向SQL数据库写入数据的脚本,但没有成功,求指点

是不是插入的语句不对呀,求指点。图片看不清的话,我把脚本复制在下面:
Option Explicit
Function action
Dim DB,objRecordSet
Dim Excel
‘SQL Server服务器地址
Dim SQLserver
‘SQL Server 数据库
Dim Database
‘SQL Server登录名
Dim uid
‘SQL Server登陆密码
Dim pwd
‘SQL Server 数据库表名
Dim Tablename
‘SQL Server数据库表列字段
Dim Column
‘Excel表路劲
Dim XLSPath
 
SQLserver = "WIN-B6MC1MBR5J8\WINCC"
Database = "test1"
uid = "sa1" 
pwd = "123"
tablename = "testtable" 
Set DB = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.RECORDSET")
Set Excel = CreateObject("Excel.Application")
DB.Open "Driver=SQL Server;server="&SQLserver&";Database="&Database&";uid="&uid&";pwd="&pwd&";"   
Dim riqi
riqi=HMIRuntime.Tags("riqi")
Dim shijian
riqi=HMIRuntime.Tags("时间")
Dim tag0
riqi=HMIRuntime.Tags("L")
Dim tag1
riqi=HMIRuntime.Tags("P")
Dim tag2
riqi=HMIRuntime.Tags("T")

 sql = "insert into "&Tablename &" VALUES (‘"&riqi&"’,’"&shijian&"’,’"&tag0&"’,’"&tag1&"’,’"&tag2&"’)"  
         
      DB.Execute(sql)  
  
End Function

图片说明:

写了个向SQL数据库写入数据的脚本,但没有成功,求指点   

最佳答案

http://bbs.bccn.net/thread-358224-1-1.html
参考这个。

提问者对于答案的评价:
谢谢

原创文章,作者:ximenziask,如若转载,请注明出处:https://www.zhaoplc.com/plc368768.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2021年7月5日 下午3:19
下一篇 2021年7月5日 下午3:19

相关推荐

发表回复

登录后才能评论