1

Wondered if any one can help with the following problem. I am using a Vbscript within Siemens WinCC. When I activate the script and the "lngValue" variable contains a string with letters "BC" it displays an error when trying to insert into database.

If the "lngValue" was blank then a insert would be made into mysql database been blank all ok. (So connections all ok even tried with INT and worked)

I get following error:

[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

The script is as follows:

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

Thanks Steve.

user692942
  • 16,398
  • 7
  • 76
  • 175
Stephen Weir
  • 11
  • 1
  • 2
  • Check the commandText string to see what's really being sent to the database - I bet you'll see the issue: MsgBox commandText – Bob Apr 05 '15 at 02:40

3 Answers3

1
objConn.Open "Driver={MySQL ODBC 5.3 ANSI Driver};Server=127.0.0.1;Database=siemens;UID=root;PWD=root"

try this

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
  • 1
    While this code snippet may solve the question, [including an explanation](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – codedge Jan 21 '21 at 15:04
0

In Wincc SmartTags are not updated when you call them into the VBScript. Probably when you build the query lngValue is empty because SmartTags("ProductRunning_Mydata.ChargehandInitials") returns an empty string. A solution to the problem could be to insert a hidden Textbox associated with the tag "ProductRunning_Mydata.ChargehandInitials" inside the screen you are in. When you enter the screen the SmartTag is forced to update.

Andrea Cattaneo
  • 568
  • 1
  • 6
  • 18
0

Steve, Make sure your field in tha database is "string" (varchar(x))

RammRras
  • 36
  • 4