WinCC. ADODB Recordset. What is wrong?

smcmanus

Member
Join Date
Jan 2006
Location
Vancouver
Posts
109
I am able to read from a database and navigate through the database using the "MoveNext" command. But in order to use the "MovePrev" command I need to set my Cursor Type to "AdOpenStatic" or a value of "3". But once I execute my statement(Refer to Line # 19) it overwrites my recordset's object value for the CursorType back to default of "0" therefore not allowing me to use the "MovePrev" command. Any help is really appreciated. Thanks...
 
Last edited:
smcmanus said:
I am able to read from a database and navigate through the database using the "MoveNext" command. But in order to use the "MovePrev" command I need to set my Cursor Type to "AdOpenStatic" or a value of "3". But once I execute my statement(Refer to Line # 19) it overwrites my recordset's object value for the CursorType back to default of "0" therefore not allowing me to use the "MovePrev" command. Any help is really appreciated. Thanks...

Hi,
I've done a little bit of ADODB work with iFix. I'm not an expert.

But I thought you first create a connection e.g

Code:
Set AdoCon = New ADODB.Connection 
AdoCon.ConnectionString = "Connection String Here"
AdoCon.Open

Then if you wanted to view the database create a recordset using an SQL query to get the required info. e.g

Code:
strSQL=""
strSQL=strSQL & "SELECT *"
strSQL=strSQL & "FROM yourDB"
strSQL=strSQL & "WHERE blah=blah"
 
Set AdoRs = New ADODB.Recordset
AdoRs.Open strSQL, AdoCon, adOpenKeyset, adLockPessimistic, adCmdText

The result of your query is then put in your recordset. To navigate through your recordset you can then use commands such as:

Code:
adoRs.movenext
adoRs.moveprev

To display the current record use:
Code:
currentfieldvalue = adoRS(fieldnumber in here)

If you show a bit of your code i may be able to help further.

Hope this helps

Rich
 
WinnCC Flexible code question
The code below is all in one script called by the main screen. I have 2 buttons. Move record forward and move Record Previous. What i need to do is call a script "MoveForward" with the move forward button and call another script "Move Previous" with the move previos button. But how to I pass my record set object "rst"? see code below! The issue I am having is I am stuck in a do until loop therefore it is not allowing me to click any objects on my screen. i.e move forward and move previos buttons. That's why if maybe I can call 2 different scrips up with passing the recordset it may be easier.





Dim conn,rst
Dim SQL_Table

Set conn = CreateObject("ADODB.Connection")
Set rst = CreateObject("ADODB.Recordset")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=c:\G&S.mdb"

rst.CursorLocation = 3
rst.CursorType = 3
rst.LockType = 3

SQL_Table = "Select * FROM tblData1"

rst.open SQL_Table,conn



Do Until strscreen <> HmiRuntime.BaseScreenName

SmartTags("LASER_2D") = rst.Fields(0).Value
SmartTags("LASER_2D_GRADE") = rst.Fields(1).Value
SmartTags("G&S_2D") = rst.Fields(2).Value


Do While SmartTags("btnNext")=True Or SmartTags("btnPrev")=True

If SmartTags("btnNext")=True Then
rst.MoveNext
SmartTags("btnNext")=False


If SmartTags("btnPrev")=True Then
rst.MovePrevious
SmartTags("btnPrev")=False


End If
End If

ActivateScreen "Screen_1",0
Loop


Loop

Set rst = Nothing
Set conn = Nothing
 
Hi,
From your code it looks like you're only displaying one record at a time. If you are, it might be better to ditch the movenext, moveprev commands (I think you only use these commands when the recordset has been put into a grid?) and modify the SQL statement so that it only retrieves on record.
Is it possible to populate a combo box with all the possible records and then use the selection of that box to decide on which record is put in your smart tasks?

Hope this helps
 
Last edited:
yeah i am starting to get behind. Basically all I am looking for now to is to populate my database. I will come up with viewing it later. Basically I have an OPC server filling text boxes. That is now problem. Once all those boxes are full I need to send it a database. Do you think doing it in script is the best way?
 

Similar Topics

Hey, Has anyone here experienced a memory leak while using ADODB to connect to an SQL (Or any other) database? I've got a WinCC C-Script that...
Replies
7
Views
6,505
Hello. I have a db which is 1000 INT, and this db is represented in WinCC as a raw data type set of 5x 400 Bytes. This set is read with a script...
Replies
1
Views
79
Hello Experts I am working on a project with WinCC Unified v16 PC system and want to create an option on the screen to export logs to the...
Replies
0
Views
68
Does anyone happen to know how to install the graphic picture in HMI when I go into blower selection there are no graphics shown not only blower...
Replies
1
Views
85
Hi folks, I'm not as accustom with Siemens & WinCC, however I've been asked to increase the amount of data an existing application is logging...
Replies
2
Views
80
Back
Top Bottom