AnsweredAssumed Answered

Passing timestep value as a parameter for OLEDB query using c#

Question asked by Suganya_Ganesan on Jul 5, 2016
Latest reply on Jul 14, 2016 by Marcos Vainer Loeff

Hi,


I have a WCF service running to fetch daily and monthly readings from PI point.


I am using the below OLEDB query to fetch interpolated value

SELECT * FROM PIARCHIVE..PIINTERP2 WHERE TAG = ? AND TIME >= ? AND TIME <= ? AND TIMESTEP = ?

When i am trying to pass the values as parameters to the query i am getting below exceptions:

 

Case 1: When the value of the Timestep parameter is "1d".

                cmd.Parameters.AddWithValue("@interval", "'1d'");

 

Exception message:

'PIOLEDB' failed with no error message available, result code: DB_E_PARAMNOTOPTIONAL(0x80040E10).


Case 2: When the value of the timestep parameter is passed as a TimeSpan object. 

 

               TimeSpan ts = new TimeSpan(1,0,0,0);
               cmd.Parameters.AddWithValue("@interval", ts);


Exception message:

Query into 'piarchive..piinterp2 piinterp2' table is invalid. Column 'timestep' cannot be set to NULL.

 

Apparently the problem is with Timestep parameter only, rest others are OK,

 

Also, the query works fine when value of timestep is passed in the query.

 

 

Please help!

 

Thanks in advance.

Outcomes