YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

PI OLEDB - Can't insert data Options · View
Marcelo Fernandez
#1 Posted : Tuesday, October 27, 2009 3:37:46 PM
Rank: Newbie
Groups: Member

Joined: 10/27/2009
Posts: 2
Location: Buenos Aires, Argentina
Hello,

I've trying to insert data through PI OLEDB with the following code:

Code:

using (OleDbConnection conn = new OleDbConnection(connstr))
{
    try
    {
        conn.Open();

        string tag = 'TI_AW1';
        DateTime timestamp = new DateTime(2009, 08, 31, 08, 10, 54);
        decimal value = 22.45;

        OleDbCommand cmd = new OleDbCommand(conn);
        string sql_insert = "INSERT INTO piarchive..picomp2 (tag, time, value, annotations) VALUES ('{0}', '{1}', {2}, 'Manually created')";
        cmd.CommandText = string.Format(sql_insert, tag, timestamp.ToString("dd-MMM-yy hh:mm:ss"), value);
        cmd.CommandType = System.Data.CommandType.Text;
        cmd.ExecuteNonQuery();
    }
    catch (Exception e)
    {
        Console.Error.WriteLine(e.Message);
    }
    finally
    {
        conn.Close();
    }
}



but when I go to ProcessBook I can saw the data for a few minutes and after that the data disapear.
What is wrong with this code or what I forget to do?

Thanks in advance.
Sponsor  
 
mrivett
#2 Posted : Tuesday, October 27, 2009 4:11:50 PM
Rank: Member
Groups: Member

Joined: 9/23/2008
Posts: 15
Location: Pennsylvania, USA
Was the tag created before or in the archive that you are writing to? If the tag was created after the archive it will not be able to save the value unless you reprocess the archive.
Marcelo Fernandez
#3 Posted : Tuesday, October 27, 2009 6:46:12 PM
Rank: Newbie
Groups: Member

Joined: 10/27/2009
Posts: 2
Location: Buenos Aires, Argentina
Thanks, you are right. Applause
I'll go to reprocess the archive. At the moment, I did a test with an old tag into disuse and is working.

Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.