????????????????SQLite for Windows Runtime (Windows 8.1)?????VS???????????Visual C++ Runtime Package(?磺Microsoft Visual C++ 2013 Runtime Package for Windows)??
????????????????????X86????X64???????????к?AnyCPU??????????????X86.
private async void Create()
{
//????????????λ??
var dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path?? "db1.sqlite");
//??????????????
using (var db = new SQLite.SQLiteConnection(dbPath))
{
//??????
var result = db.CreateTable<Model.Person>();
await new MessageDialog("???????" + result).ShowAsync();
}
}
private async void Insert()
{
//?????????
var dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path?? "db1.sqlite");
using (var db = new SQLite.SQLiteConnection(dbPath))
{
//????????????????????????
ObservableCollection<Person> Collection = new ObservableCollection<Person>();
//???????????
db.Insert(new Person() { FirstName = "??????1"?? LastName = "Sindrol" });
Collection.Add(new Person() { FirstName = "??????2"?? LastName = "Sindrol1" });
Collection.Add(new Person() { FirstName = "??????3"?? LastName = "Sindrol2" });
//??????????
var result = db.InsertAll(Collection);
await new MessageDialog("???????" + result).ShowAsync();
}
}
private async void Update()
{
//???????
var dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path?? "db1.sqlite");
using (var db = new SQLite.SQLiteConnection(dbPath))
{
SQLiteCommand cmd = db.CreateCommand("update person set FirstName='lisa' where LastName='Sindrol'");
var result = cmd.ExecuteNonQuery();
await new MessageDialog("???????" + result).ShowAsync();
}
}
private async void Delete()
{
var dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path?? "db1.sqlite");
using (var db = new SQLite.SQLiteConnection(dbPath))
{
//???????????
db.Delete<Person>(1);
//???????
var result = db.DeleteAll<Person>();
await new MessageDialog("???????" + result).ShowAsync();
}
}
private async void Select()
{
var dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path?? "db1.sqlite");
using (var db = new SQLite.SQLiteConnection(dbPath))
{
//??????????????UI
List<object> list = db.Query(new TableMapping(typeof(Person))?? "select *  from  Person");
gridView.ItemsSource = list;
}
}