1 Reply Latest reply on Sep 17, 2012 10:44 AM by Sam Pride

    Retrieve Data state values from PI OLEDB using C#




      Firstly, this is my first time posting on these forums so please forgive my ignorance.


      I have been learning PI for about 2 months now and am starting to get to grips with it, although I would still consider myself a beginner.


      My query relates to using PI SDK to search for and display archive values from PI OLEDB.


      I've got a basic program that opens a connection to OLEDB and searches  tags based on an input text file.


      This all works fine until I get to tags that have a digital state for there values, I get  results like '-458754'


      It is my understanding that PI stores digital state values like this, a negative 6 digit number, and  converts it back when displayed.


      If this is the case, how can I use PI SDK to either get the actual string of the digital state or use C# to convert it from the stored value back to the digital state value?


      Any advice would be appreciated.




      EDIT: I believe I found the answer, I can use the DIGSTRING sql command to convert a digital state code to a name when I query OLEDB 







        • Re: Retrieve Data state values from PI OLEDB using C#
          Sam Pride

          Is there any reason why you are combining PISDK and OLEDB? They are designed to be used on their own, not combined.


          You can easily convert a Digital value to it's string equivalent in PI-OLEDB. Here's a simple sample taken from the PI-OLEDB Tester (Which is included with the PI-OLEDB provider and contains a great set of examples to get you started)





          SELECT tag, time, DIGSTRING(CAST(value AS Int32)) value, DIGSTRING(status) status
          FROM piarchive..picomp2 WHERE tag = 'cdm158' AND time >= 't'



          Edit> just realised you worked it out on your own! Great!