[?]: WinCC MSQL script

ProTool, WinCC flexible, WinCC, PP/OP/TP/TD/MP
Post Reply
Talaaaat
Posts: 2
Joined: Mon Nov 24, 2014 7:15 pm

[?]: WinCC MSQL script

Post by Talaaaat » Thu Nov 22, 2018 8:55 am

Now I want to make a I/O filed in wincc with a string format and I put it into a database

I created an internal tag with text char 16 and link it to the I/O filed and the output of this I/O field is string

I tested the link between the Wincc and the database and it is worked and recording another data types of real data format

But I tried to send the field with the string data type, it didn't work

The database column which I created was with nvarchar

Please check attached script of the button, can anybody help me to check where is the error

Code: Select all

Sub OnLButtonDown(ByVal Item, ByVal Flags, ByVal x, ByVal y)                  
Dim objConnection
Dim strConnectionString
Dim teto
Dim tetoo
Dim tetooo
Dim tetoooo


Dim strSQL
Dim objCommand
strConnectionString = "Provider=MSDASQL;DSN=Demo;UID=;PWD=;"
teto = HMIRuntime.Tags("nitro").Read
tetoo = HMIRuntime.Tags("watter").Read
tetooo = HMIRuntime.Tags("elec").Read
tetooo = HMIRuntime.Tags("delay").Read

strSQL = "INSERT INTO Table_1 (nit, water, elect,delay) VALUES (" & teto & "," & tetoo & "," & tetooo & "," & tetoooo & ");"
Set objConnection = CreateObject("ADODB.Connection")
objConnection.ConnectionString = strConnectionString
objConnection.Open
Set objCommand = CreateObject("ADODB.Command")
With objCommand
.ActiveConnection = objConnection
.CommandText = strSQL
End With
objCommand.Execute
Set objCommand = Nothing
objConnection.Close
Set objConnection = Nothing
End Sub

yaqui
Posts: 22
Joined: Thu Aug 30, 2012 8:37 pm

Re: [?]: WinCC MSQL script

Post by yaqui » Fri Nov 23, 2018 9:56 am

If you are working with SQL Server your string must be like this:
string : ' " & varString & " '
number: " & varNumber & "
strSQL = "INSERT INTO Table_1 (nit, water, elect,delay) VALUES ('" & teto & "','" & tetoo & "','" & tetooo & "','" & tetoooo & "');"

Rex2701
Posts: 253
Joined: Wed Oct 13, 2010 8:44 am
Location: Russian Federation

Re: [?]: WinCC MSQL script

Post by Rex2701 » Fri Nov 23, 2018 2:26 pm

Talaaaat wrote:Please check attached script of the button, can anybody help me to check where is the error
You read two tags into the same variable:

Code: Select all

...
tetooo = HMIRuntime.Tags("elec").Read
tetooo = HMIRuntime.Tags("delay").Read
...

Post Reply