Rt/metro Store app How to call the SQLite database

Source: Internet
Author: User
Tags sqlite sqlite database

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.