public void UpdateDefinition(string old_keyword, bool is_insert) { using (SQLiteConnection conn = new SQLiteConnection(ConfigurationManager.ConnectionStrings["BudgetDataConnectionString"].ConnectionString)) { string qry = "DELETE FROM Definitions WHERE keyword = @keyword"; using (SQLiteCommand cmd = new SQLiteCommand(qry, conn)) { cmd.Parameters.Add("@keyword", DbType.String, 100).Value = old_keyword; conn.Open(); cmd.ExecuteNonQuery(); if (is_insert) { qry = "INSERT INTO Definitions (category, keyword, id) SELECT @category, @keyword, Entries.id FROM Entries WHERE description LIKE " + (Keyword.StartsWith("~") ? "" : "'%' ||") + " @keyword2 " + (Keyword.EndsWith("~") ? "" : "|| '%'"); cmd.CommandText = qry; cmd.Parameters.Add("@category", DbType.String, 100).Value = Category; cmd.Parameters.Add("@keyword", DbType.String, 100).Value = Keyword; cmd.Parameters.Add("@keyword2", DbType.String, 100).Value = Keyword.Replace("~", ""); cmd.ExecuteNonQuery(); } conn.Close(); } } }