I have inserted a lot of information into a SQlite database from my program. Now, my small task is to look up the database and find some statistics from it.
Ex: I have a database with three fields – Timestamp, Message and Key
Now, I want to check the database in the Message column and count the number of times a certain keyword(say “ERROR”) occurs in the database.
What is the simplest way to do this?
SELECT Message from Database and how do i add the filter???
I use Regex to filter out some stuff before Insert. Should i do something similar here?
Thanks
Edit:
I used the solution mentioned below SELECT count(*) but am still unaware of how to get the value out to use it in another function. I have shown the code i used below. I am new to SQL and it possibly is wrong. Please help!
public void selectFromDatabase()
{
String cntnStr_query = "data source=C:\\TMU_Files\\test31.s3db";
SQLiteConnection connection_query = new SQLiteConnection(cntnStr_query);
connection_query.Open();
SQLiteCommand cmd_query = connection_query.CreateCommand();
cmd_query.CommandText = "SELECT count(*) from LogDatabase where LogMessage like '%ERR%'";
SQLiteDataAdapter da_query = new SQLiteDataAdapter(cmd_query);
DataSet ds_query = new DataSet();
//MessageBox.Show(cmd_query.ExecuteNonQuery().ToString());
//MessageBox.Show(count.ToString());
try
{
da_query.Fill(ds_query);
DataTable dt_query = ds_query.Tables[0];
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
finally
{
cmd_query.Dispose();
connection_query.Close();
}
//cmd_query.Dispose();
//connection_query.Close();
}
}
}
As to how it should look like in code, try something like this: