Unable to select last Active Alarm
Posted: Wed Feb 12, 2020 6:15 am
I am trying to select the last active alarm using following script.
void Screen2_Opened(System.Object sender, System.EventArgs e)
{
SQLiteConnection db = new SQLiteConnection("DataSource=Database.db");
string query ="Select [Text] from AlarmServer WHERE State = 'Active' ORDER BY ActiveTime DESC LIMIT 1";
SQLiteCommand comm = new SQLiteCommand(query);
comm.Connection = db;
db.Open();
SQLiteDataReader read = (null);
read = comm.ExecuteReader();
while (read.Read())
{
Globals.Tags.AlarmString.Value = (read["Text"].ToString());
}
read.Close();
db.Close();
}
But it always select Last-1 alarm and show its text in AlarmString tag. Where am I doing wrong?
I have also attached the project for reference.
void Screen2_Opened(System.Object sender, System.EventArgs e)
{
SQLiteConnection db = new SQLiteConnection("DataSource=Database.db");
string query ="Select [Text] from AlarmServer WHERE State = 'Active' ORDER BY ActiveTime DESC LIMIT 1";
SQLiteCommand comm = new SQLiteCommand(query);
comm.Connection = db;
db.Open();
SQLiteDataReader read = (null);
read = comm.ExecuteReader();
while (read.Read())
{
Globals.Tags.AlarmString.Value = (read["Text"].ToString());
}
read.Close();
db.Close();
}
But it always select Last-1 alarm and show its text in AlarmString tag. Where am I doing wrong?
I have also attached the project for reference.