1. Right-click to reference the nuget package and install vici coolstorage
2. You can see two more files in the reference: vici. coolstorage. WP8 and vici. Core. WP8.
3,
Public class SQLite
{
Private Static SQLite _ instance;
Public static SQLite getinstance ()
{
If (_ instance = NULL)
_ Instance = new SQLite ();
Return _ instance;
}
Public SQLite ()
{
}
///// <Summary>
//// Pass! Istorage. fileexists (FN) guarantees the program's first time
///// The database will be copied only when running
//// To the isolated bucket,
//// FN indicates the copied database path and name
///// </Summary>
///// <Param name = "FN"> </param>
// Private void move (string FN)
//{
/// Streamresourceinfo sr = application. getresourcestream (New uri (FN, urikind. Relative ));
// Isolatedstoragefile istorage = isolatedstoragefile. getuserstoreforapplication ();
// If (! Istorage. fileexists (FN ))
//{
// Using (VAR outputstream = istorage. openfile (FN, system. Io. filemode. createnew ))
//{
// Byte [] buffer = new byte [1, 10000];
// (;;)
//{
// Int READ = Sr. Stream. Read (buffer, 0, buffer. Length );
// If (read <= 0)
// Break;
// Outputstream. Write (buffer, 0, read );
//}
//}
//}
//}
/// <Summary>
/// Store the file to an independent Bucket
/// </Summary>
/// <Param name = "assemblyname"> project name </param>
/// <Param name = "dbname"> file name </param>
Private void copyfromcontenttostorage (string assemblyname, string dbname)
{
Isolatedstoragefile store = isolatedstoragefile. getuserstoreforapplication ();
System. Io. Stream src = application. getresourcestream (New uri ("/" + assemblyname + "; component/database/" + dbname, urikind. Relative). stream;
Isolatedstoragefilestream DEST = new isolatedstoragefilestream (dbname, system. Io. filemode. openorcreate, system. Io. fileaccess. Write, store );
SRC. Position = 0;
Copystream (SRC, DEST );
DeST. Flush ();
DeST. Close ();
SRC. Close ();
DeST. Dispose ();
}
/// <Summary>
/// Copy the stream
/// </Summary>
/// <Param name = "input"> </param>
/// <Param name = "output"> </param>
Private Static void copystream (system. Io. Stream Input, isolatedstoragefilestream output)
{
Byte [] buffer = new byte [32768];
Long temppos = input. position;
Int readcount;
Do
{
Readcount = input. Read (buffer, 0, buffer. Length );
If (readcount> 0)
{
Output. Write (buffer, 0, readcount );
}
} While (readcount> 0 );
Input. Position = temppos;
}
/// <Summary>
/// Query all data in the region information table
/// </Summary>
/// <Param name = "stablename"> table name </param>
/// <Param name = "swhere"> query condition </param>
/// <Param name = "sorder"> </param>
/// <Returns> </returns>
Public csgenericrecordlist queryalldata (string sselect, string stablename, string swhere, string sorder)
{
String strsql = string. empty;
Strsql + = "select" + sselect + "from" + stablename;
If (! Swhere. Equals (""))
{
Strsql = strsql + "where" + swhere;
}
If (! Sorder. Equals (""))
{
Strsql = strsql + "order by" + sorder;
}
// Move (FN );
Copyfromcontenttostorage ("pingan_wp", "financialtel. DB ");
// Set the database used
Csconfig. setdb ("financialtel. DB ");
Csgenericrecordlist arealist = csdatabase. runquery (strsql );
Return arealist;
}
}
4. Call
Protected override void onnavigatedto (navigationeventargs E)
{
SQLite sqllite = new SQLite ();
Csgenericrecordlist cslis = sqllite. queryalldata ("distinct level2, tel", "Pingan", "level3 ='' "," sort ");
Lb_main.itemssource = from CS in cslis select new pingan_model (CS ["level2"]. tostring (), CS ["tel"]. tostring ());
// Pingan_model is an object
Base. onnavigatedto (E );
}