plcforum.uz.ua

International PLC Forum
It is currently Mon Dec 17, 2018 10:39 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: [?]: WinCC MSQL script
PostPosted: Thu Nov 22, 2018 11:55 am 

Joined: Mon Nov 24, 2014 10:15 pm
Posts: 2
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:
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


Top
 Profile  
 
PostPosted: Fri Nov 23, 2018 12:56 pm 

Joined: Thu Aug 30, 2012 11:37 pm
Posts: 22
Talaaaat wrote:
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:
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



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 & "');"


Top
 Profile  
 
PostPosted: Fri Nov 23, 2018 5:26 pm 

Joined: Wed Oct 13, 2010 11:44 am
Posts: 237
Location: Russian Federation
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:
...
tetooo = HMIRuntime.Tags("elec").Read
tetooo = HMIRuntime.Tags("delay").Read
...


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by International PLCforum® Forum Software © PLCforum
Mobile version