citect scada and sql

salamplc

Member
Join Date
Jan 2019
Location
ir
Posts
9
hi.
I want to connect to sql server and i get data from it and i show it on textbox in citect scada 2018.i have this code for this task.data does not show on textbox.please say your idea for me.





INT
FUNCTION
GetNames()
INT hSQL;
STRING sName;
INT Status;

hSQL = SQLConnect( "DSN=impaytere_ss" );
IF hSQL <> -1 THEN
Status = SQLExec( hSQL,"SELECT CNAME FROM FETISH WHERE SURNAME = 'Jumpy' " );
IF Status = 0 THEN
WHILE SQLNext( hSQL ) = 0 DO
sName = SQLGetField( hSQL, "CNAME" );

// whatever you wish to do with this data...

END;
SQLEnd( hSQL );

ELSE
Message( "Error", SQLErrMsg(), 48 );
END;

ELSE
Message( "Error", SQLErrMsg(), 48 );
END;
RETURN sName
SQLDisconnect( hSQL );
END
 
Where are you trying to execute the GetNames function?

You did INT function, which expects to return an integer, not a string.


hi
thank you for your answer


i made a textbox object in citect graphic builder and i opened textbox properties window."sName" variable put in "string expression" part in "appearance" tab in textbox properties.also GetNames function put in "up command" part in "input" tab in textbox properties.
i delete int in first code line but i con not see database value in text box.
when i run my citect project ,i show a empty textbox .when cursor is put on textbox,i show "good" notification on textbox
 
SQL Exec is to run a stored procedure if that procedure does not exist it will not work.
I suggest you iterate through the data & compare
or use the select

SELECT Name
FROM Customer
WHERE Name = 'John'
However this may return more than one unless the Name is unique.
Also your while next statement may move the pointer to the next field
 
SQL Exec is to run a stored procedure if that procedure does not exist it will not work.
I suggest you iterate through the data & compare
or use the select

SELECT Name
FROM Customer
WHERE Name = 'John'
However this may return more than one unless the Name is unique.
Also your while next statement may move the pointer to the next field


hi
thank you for your reply .
i used "select" in my code.there are data in table according to select function.i sent my table by attachment.

photo_2019-06-24_14-31-05.jpg
 
I have never used that SCADA so do not know the SQL Functions
This is what I did as a quick check in another Scada but totally in Basic

Dim Rs1 As New ADODB.Recordset
Dim Conn1 As New ADODB.Connection
Dim SQLStr, First_Name As String

Sub Main()

Conn1.ConnectionString = "dsn=Names;uid='sa';pwd='';"
SQLStr = "SELECT CNAME FROM FETISH WHERE SURNAME = 'Jumpy'"
Conn1.Open
Rs1.Open SQLStr,Conn1,,,
First_Name = Rs1.Fields(0).Value
Rs1.Close
Set Rs1 = Nothing
Conn1.Close
Set Conn1 = Nothing

End Sub

I created your Database and then run this script and it returned "Jill" in my variable First_Name however I did not include any error checking
 
I have never used that SCADA so do not know the SQL Functions
This is what I did as a quick check in another Scada but totally in Basic

Dim Rs1 As New ADODB.Recordset
Dim Conn1 As New ADODB.Connection
Dim SQLStr, First_Name As String

Sub Main()

Conn1.ConnectionString = "dsn=Names;uid='sa';pwd='';"
SQLStr = "SELECT CNAME FROM FETISH WHERE SURNAME = 'Jumpy'"
Conn1.Open
Rs1.Open SQLStr,Conn1,,,
First_Name = Rs1.Fields(0).Value
Rs1.Close
Set Rs1 = Nothing
Conn1.Close
Set Conn1 = Nothing

End Sub

I created your Database and then run this script and it returned "Jill" in my variable First_Name however I did not include any error checking




hi
thank you for your reply
how to configure database to connect citect scada by ado.net?
 
Last edited:
The SQL commands native to Citect work fine. I wouldn't bother trying to figure out how to get ADO.Net to interface to the database.

hi
Thank you for your reply
I would like to use ado.net but i do not know about configuring it.do you have any document for it?.
 
You need to change the SQLExec to this I think

SQLExec(hSQL, "SELECT * FROM FETISH WHERE SURNAME = 'Jumpy'");
If SQLNext(hSQL) = 0 Then
sName = SQLGetField( hSQL, "CNAME" );

END
 

Similar Topics

hi. I want to connect to sql server and i get data from it and i show it on textbox in citect scada 2018.i have this code for this task.data...
Replies
1
Views
1,594
Hello all! I am new in Citect SCADA. I need to create material tracking system in which I have a dozen of photometric sensors. When each sensor...
Replies
1
Views
2,958
I am trying to display a variable within a cicode function onto a graphics page. This function queries a SQL database. I can get the value onto a...
Replies
3
Views
229
We are trying to set up a newer generation Omron PLC (NX/NS Series) with Citect / Aveva Plant SCADA using the Ethernet/IP CIP Protocol to read...
Replies
2
Views
267
I am new to Citect SCADA and I am building the graphics for a page that will contain the control of a plant by a Kingfisher RTU. The project I...
Replies
0
Views
219
Back
Top Bottom