Reputation: 4342
This code will create the Database in : LocalFolder
string DBPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "customers.sqlite");
using (var db = new SQLite.SQLiteConnection(DBPath))
{
// Create the tables if they don't exist
db.CreateTable<Customer>();
db.CreateTable<Item>();
}
The problem:
How to delete the customers.sqlite ( Database created ) so that this will reset all Primary Key to starting number like 0.
using (var db = new SQLite.SQLiteConnection(DBPath))
{
db.DeleteAll<Customer>();
db.DeleteAll<Item>();
}
Upvotes: 1
Views: 1858
Reputation: 11
This code can reset Primary key, but if you need delete db, just delete sqlite-db file.
using (var db = new SQLite.SQLiteConnection(localBaseConnection))
{
db.DropTable<YourTableName>();
db.CreateTable<YourTableName>();
db.Dispose();
db.Close();
}
Upvotes: 1
Reputation: 15296
With this queries you can clear the table & then reset auto increment column.
using (var db = new SQLiteConnection(ApplicationData.Current.LocalFolder.Path + "\\db.sqlite"))
{
db.Query<your_table_name>("delete from your_table_name", "");
db.Query<sqlite_sequence>("delete from sqlite_sequence where name = ?", "your_table_name");
}
You also have to add this class.
public class sqlite_sequence
{
public string name { get; set; }
public int seq { get; set; }
}
Upvotes: 0
Reputation: 180240
To ensure that autoincrement valures are reset, you can either delete the database file, or drop the tables.
Upvotes: 0