想知道是否有人可以幫助解決以下問題。我在西門子WinCC內使用Vbscript。當我激活腳本並且「lngValue」變量包含一個字母爲「BC」的字符串時,它會在嘗試插入數據庫時顯示錯誤。西門子WinCC VBscript到Mysql
如果「lngValue」是空的,那麼一個插入操作會被導入到mysql數據庫中,一直空白。 (所以連接一切OK,即使INT嘗試和努力)
我獲得以下錯誤:
[MySQL][ODBC 5.3(a) Driver][mysqld-5.6.19]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near "BC' at line 1
的腳本如下:
Sub Writetomysql()
Dim lngValue
Dim lngValue1
Dim commandText
Dim objConn
Dim objRS
Set objConn = CreateObject("ADODB.Connection")
objConn.Open "Driver={MySQL ODBC 5.3 ANSI Driver};Server=127.0.0.1;Database=siemens;UID=root;PWD=root;OPTION=3;"
Set objRS = CreateObject("ADODB.Recordset")
lngValue = SmartTags("ProductRunning_Mydata.ChargehandInitials")
lngValue1 = HMIRuntime.Tags("PPM").Read
commandText = "INSERT INTO products (ProductName, PPM) VALUES ('" _
& lngValue & "','" & lngValue1 & "')"
If SmartTags("FinishButton") = 1 Then
objRS.Open "products", objConn
objConn.Execute commandText
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
End If
End Sub
感謝史蒂夫。
稍候...誰是史蒂夫?你爲什麼感謝他? – eggyal 2015-04-04 16:56:01
檢查commandText字符串以查看真正發送到數據庫的內容 - 我打賭你會看到問題:MsgBox commandText – Bob 2015-04-05 02:40:24