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