Rt/metro Store app How to call the SQLite database before you use it to install:
SQLite for Windows Runtime (Windows 8.1)(A vs plugin), and
Visual C + + Runtime Package(For example: Microsoft Visual C + + Runtime package for Windows), and project builds to be modified to X86 or X64, in short, cannot be made with and anycpu. I'm using X86 here.
Private Async voidCreate () {//where the data file is saved varDbPath = Path.Combine (Windows.Storage.ApplicationData.Current.LocalFolder.Path,"Db1.sqlite"); //open CREATE DATABASE and table using(vardb =Newsqlite.sqliteconnection (DbPath)) { //Create a table varresult = db. Createtable<model.person>(); await NewMessagedialog ("return Value:"+result). Showasync (); } } Private Async voidInsert () {//connecting to a database varDbPath = Path.Combine (Windows.Storage.ApplicationData.Current.LocalFolder.Path,"Db1.sqlite"); using(vardb =Newsqlite.sqliteconnection (DbPath)) { //The insert operation. First declare a collectionObservablecollection<person> Collection =NewObservablecollection<person>(); //Single INSERT statementDb. Insert (NewPerson () {FirstName ="Song Xingju 1", LastName ="Sindrol" }); Collection.add (NewPerson () {FirstName ="Song Xingju 2", LastName ="Sindrol1" }); Collection.add (NewPerson () {FirstName ="Song Xingju 3", LastName ="Sindrol2" }); //Multiple Insertion sets varresult =db. Insertall (Collection); await NewMessagedialog ("return Value:"+result). Showasync (); } } Private Async voidUpdate () {//UPDATE statement varDbPath = Path.Combine (Windows.Storage.ApplicationData.Current.LocalFolder.Path,"Db1.sqlite"); using(vardb =Newsqlite.sqliteconnection (DbPath)) {Sqlitecommand cmd= db. CreateCommand ("Update person set firstname= ' Lisa ' where Lastname= ' Sindrol '"); varresult =cmd. ExecuteNonQuery (); await NewMessagedialog ("return Value:"+result). Showasync (); } } Private Async voidDelete () {varDbPath = Path.Combine (Windows.Storage.ApplicationData.Current.LocalFolder.Path,"Db1.sqlite"); using(vardb =Newsqlite.sqliteconnection (DbPath)) { //Single-line delete operationDb. Delete<person> (1); //multi-line deletion varresult = db. Deleteall<person>(); await NewMessagedialog ("return Value:"+result). Showasync (); } } Private Async voidSelect () {varDbPath = Path.Combine (Windows.Storage.ApplicationData.Current.LocalFolder.Path,"Db1.sqlite"); using(vardb =Newsqlite.sqliteconnection (DbPath)) { //querying all data binding to the UIlist<Object> list = db. Query (NewTableMapping (typeof(person)),"SELECT * from person"); Gridview.itemssource=list; } }
The person class looks like this:
class person { [Sqlite.autoincrement, Sqlite.primarykey] publicintgetset ; } Public string Get Set ; } Public string Get Set ; } }
Database:
Rt/metro Store app How to call the SQLite database