恭喜,你发布的帖子
发布于 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
请填写推广理由:
分享
只看
楼主