7 Replies Latest reply on Mar 10, 2010 1:29 AM by ACL427

    Display Data in a Grid Control?

    ACL427

      Hi,

       

      I have a requirement to display data in a ProcessBook in a data grid or an updating tabular format.  The goal is to show say the last 10 values for 1 or more tags in an updating grid. Similar to what you see in the 'Details' pane but with the flexibility to format it on the display they way you might a table.

       

      One thing that comes to mind is to use an OLEDB query and send the results to a data grid control. Not really sure if that is the best way to tackle this but it seems like a reasonable approach. 

       

      Are there other options? Any other places I should be looking for a quick start?

       

      Thanks for any suggestions!

        • Re: Display Data in a Grid Control?

          You could use some logic to arrange symbols on a display.

           

          or

           

          You could embed an Excel Worksheet using the Microsoft Office Web Components.

          • Re: Display Data in a Grid Control?
            MichaelvdV@Atos

            Andrew

            One thing that comes to mind is to use an OLEDB query and send the results to a data grid control. Not really sure if that is the best way to tackle this but it seems like a reasonable approach. 

             

            I think that will be a good choice! To have the updates, you can use a timer to execute the query once every <interval>.

              • Re: Display Data in a Grid Control?

                I too like to think the PI OLEDB Provider is best suited to do that type of "relational", grid-type of requests. That's a very simple way to achieve BUT requires that the PI OLEDB Provider be installed on all client machines where you run that PI ProcessBook display.

                 

                Just drop a data grid (Microsoft DataGrid Control) on the ProcessBook display, then a button (or a timer) that executes code similar this:

                Private Sub cmdRead_Click()
                    Dim Cn As New ADODB.Connection
                    Dim Rs As New ADODB.Recordset
                   
                    Cn.Open "Provider=PIOLEDB; Data Source=yourPIServer; Integrated Security=SSPI;"
                    Rs.Open "SELECT tag, time, value FROM picomp WHERE time >= '*-1h' and tag = 'cdt158'", Cn, adOpenStatic
                    Set grdValues.DataSource = Rs
                End Sub

                The above would show the last hour worth of values for PI Point 'cdt158'.

                 

                Such an approach allows you to easily write values to PI too:

                Private Sub cmdWrite_Click()
                    Dim Cn As New ADODB.Connection
                    Dim Cmd As New ADODB.Command

                    Cn.Open "Provider=PIOLEDB; Data Source=yourPIServer; Integrated Security=SSPI;"
                    Set Cmd.ActiveConnection = Cn
                    Cmd.CommandText = "INSERT INTO picomp (tag, time, value) VALUES ('cdt158','" & txtTime.Text & "'," & txtValue.Text & ")"
                    Cmd.Execute
                End Sub

                  • Re: Display Data in a Grid Control?
                    ACL427

                    Thanks Steve,

                     

                    I'm getting an error 'user defined type not defined' when I try and run this on the line Dim Rs As New ADODB.Recordset.  I don't have a timer control so I'm trying to kick this off the data update event of a value item. In either case I get the same result.  Any ideas?

                     

                    This will probalby be on a static display so adding OLEDB to that machine is an option for me if that gives me more options.

                      • Re: Display Data in a Grid Control?
                        hanyong

                        Hi Andrew,

                         

                        Which library did you reference to use the ADODB objects? "Microsoft ActiveX Data Objects 2.8 Library" seems to work fine for me.

                         

                        Han Yong

                          • Re: Display Data in a Grid Control?
                            ACL427

                            Ah, yes. I had the reference wrong.

                             

                            I'm struggling with one final issue on this.  I'm able to get this to return data to the grid using test data but not production data.

                             

                            For example:

                             

                             

                             Rs.Open "select c.value as ACTION, i.value As CATEGORY , c.time FROM piarchive..picomp2 c INNER JOIN piarchive..piinterp2 i ON i.time = c.time WHERE c.tag = 'sinusoid' AND c.time >= '1/1/2010' AND i.tag = 'sinusoidu'", Cn, 1

                             

                            will return data correctly to the grid when the Value.DataUpdate fires.

                             

                             

                             

                            However, if I substitute the tag names with my real tag names I get no result and find the error "Current Recordset Does not suport updating"

                             

                            Both queries return the expected data in OLEDB tester. 

                             

                            Any suggestions are very much appreciated!!