I have a SQLite database that is displayed in a data grid view in my c# windows form. So, this database has four columns. My particular interest is in only one of the columns. The column indicates the type of message. It can be ERRORS or ALARMS or INITIALIZATION etc.. Now I have added functionality where the column can be edited and updated in the database.
Its like , I choose a list of ALARMS and then group them as ALARM # 1 (their type field is updated). Similarly ALARM # 2 and so on…
All this works fine. The problem is when I want to count the number of Alarms. I send a query
using(var sda=new SQLiteDataAdapter("SELECT count(*) from LogDatabase where Type like '%ALARM%'", "data source=" + database_path))
{
var dt = new DataTable();
int sum_rows_selected=0;
sda.Fill(dt);
int alarms_total = Convert.ToInt16(dt.Rows[0][0]);
MessageBox.Show(alarms_total.ToString());
}
This shows all the fields with ALARM in it.. So, Initially if the DB had 10 rows of Type ALARMS. It shows 10 which is fine. But now when i edit 4 rows as ALARM # 1 and 5 rows as ALARM # 2.. I want the count to be 3 ( #1 as 1, #2 as 1 and rest of ALARMS (1 here) )…
I managed to get some weird logic to get the correct answer but this works only if the ALARMS are edited to #1 or #2 at that time. If i close the window and come back it doesnt work. It shows 10 again…
Help Please
Thanks
Try grouping them:
Not sure if the syntax is different for SQLite, but something like
This should give you
My C# is rusty, but to get all the rows for both columns you would need a loop, or a data table, or a lot more variables. Forgive me if I botch up the syntax.