How to read existing sqllite Databases

Source: Internet
Author: User

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 );
}

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.