在WINCC中通过VBS链接SQL数据库,并向其中插入数据,在手册和帮助中都有讲到,当我插入的列数据都是FLOAT型,SQL数据库中对应的表的列的数据类型是REAL型时,插入数据可以实现,但是当我把第一个插入的数据类型改成16位文本时,对应的数据库中的表的第一列的数据类型采用了NCHAR,VARCHAR等都尝试了,都实现不了插入值动作,脚本诊断也没有错,且把第一个插入的数据在脚本内用字符串常数代替也可以插入,感觉问题应该出现在第一个数据类型上,但始终没有解决,请高人赐教,附上脚本如下:
Sub OnLButtonUp(Byval Item, Byval Flags, Byval x, Byval y)
Dim objConnection
Dim strConnectionString
Dim id,lngValue1,lngValue2,lngValue3,lngValue4
Dim strSQL
Dim objCommand
strConnectionString = "Provider=MSDASQL;DSN=userdata;UID=administrator;PWD=;"
id = HMIRuntime.Tags("meterial").Read '16 charecter text type
lngValue1 = HMIRuntime.Tags("t1").Read '32 float type
lngValue2 = HMIRuntime.Tags("t2").Read '32 float type
lngValue3 = HMIRuntime.Tags("t3").Read '32 float type
lngValue4 = HMIRuntime.Tags("t4").Read '32 float type
strSQL = "INSERT INTO table1 (name,tag1,tag2,tag3,tag4) VALUES (" & id & "," & lngValue1 & "," & lngValue2 & "," & lngValue3 & "," & lngValue4 & ");"
Set objConnection = CreateObject("ADODB.Connection")
objConnection.ConnectionString = strConnectionString
objConnection.Open
Set objCommand = CreateObject("ADODB.Command")
With objCommand
.ActiveConnection = objConnection
.CommandText = strSQL
End
objCommand.Execute
Set objCommand = Nothing
objConnection.Close
Set objConnection = Nothing
End Sub
请帮忙分析,看第一个数据类型和数据库中的第一列的数据类型如何设置才能向其内插入一个字符串字段。谢谢!