Developing apps with Xamarin + C #-using SQLite for local storage

Source: Internet
Author: User

1. Download Sqlite.cs:

Https://github.com/praeclarum/sqlite-net/blob/master/src/SQLite.cs

2. Create a Test entity:


    [Table ("Items")]    public class-Stock    {        [PrimaryKey, AutoIncrement, Column ("_id")] public        int ID {get; set;}        [MaxLength (8)]        public string Symbol {get; set;}    }

3. Example
3.1 Defining the Path
3.2 Creating a connection
3.3 Creating a Table
3.4 Inserting entities
3.5 Printing Results

The sample code is as follows:


String DbPath = String. Format ("{0}//{1}", Environment.getfolderpath (Environment.SpecialFolder.Personal), "Ormdemo            . db3 ");            var db = new Sqliteconnection (DbPath); Db.            Createtable<stock> (); if (!db. Table<stock> (). Any ()) {//Only insert the data if it doesn ' t already exist var newstock = new S                tock {Symbol = "AAPL"}; Db.                Insert (Newstock);                Newstock = new Stock {Symbol = "GOOG"}; Db.                Insert (Newstock);                Newstock = new Stock {Symbol = "MSFT"}; Db.            Insert (Newstock);            }//console.writeline ("Reading data");            var sb = new StringBuffer (); var table = db.            Table<stock> (); foreach (var s in table) {sb.            Append (S.id + "" + S.symbol); } return SB. ToString ();


Developing apps using Xamarin + C #-using SQLite for local storage

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.