SQLiteDatabase.Delete C# (CSharp) Method

Delete() public method

Allows the programmer to easily delete rows from the DB.
public Delete ( String tableName, String where ) : bool
tableName String The table from which to delete.
where String The where clause for the delete.
return bool
    public bool Delete(String tableName, String where)
    {
        Boolean returnCode = true;
        try
        {
            this.ExecuteNonQuery(String.Format("delete from {0} where {1};", tableName, where));
        }
        catch (Exception fail)
        {
            MessageBox.Show(fail.Message);
            returnCode = false;
        }
        return returnCode;
    }

Usage Example

        /// <summary>
        ///     Handles the Click event of the btnDelete control. Deletes all the specified Team Box Score, as well as any corresponding
        ///     Player Box Scores, from the database.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">
        ///     The <see cref="RoutedEventArgs" /> instance containing the event data.
        /// </param>
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            var r =
                MessageBox.Show(
                    "Are you sure you want to delete this/these box score(s)?\n" + "This action cannot be undone.\n\n"
                    + "Any changes made to Team Stats by automatically adding this/these box score(s) to them won't be reverted by its deletion.",
                    "NBA Stats Tracker",
                    MessageBoxButton.YesNo);

            if (r == MessageBoxResult.Yes)
            {
                foreach (var bse in dgvBoxScores.SelectedItems.Cast <BoxScoreEntry>().ToList())
                {
                    if (bse != null)
                    {
                        var id = bse.BS.ID;

                        _db.Delete("GameResults", "GameID = " + id);
                        _db.Delete("PlayerResults", "GameID = " + id);
                    }

                    _bsHist.Remove(bse);
                    MainWindow.BSHist.Remove(bse);
                }
            }
        }
All Usage Examples Of SQLiteDatabase::Delete