Basic use of wp8.1 SQLite

Source: Internet
Author: User

SQLite is a lightweight relational database, it is because of its small, mobile platform is widely used, but not suitable for processing large amounts of data and bulk operations. Its bottom layer is written in C, originally designed to be used in embedded, resource-intensive and easy-to-use, and most of the programming language can be very well combined. In. NET, its SDK supports LINQ implementations and is more convenient to use.

SDK installation.

After the installation, we refer to the DLL.

This error occurs because the SDK supports only arm and 32-bit compilation environments.

You can select the platform target as 32-bit through the project properties.

The next step is to install sqlite-net, which can be the shell command for the package console.

At this time, two CS files will appear in our project.

Next, let's verify the SDK by first creating a Table object.

1 usingSystem;2 usingSQLite;3 4 namespaceFY. Weather.datamodel5 {6[Table ("Temp")]7      Public classTemp8     {9 [PrimaryKey, AutoIncrement]Ten          Public intId {Get;Set; } One  A          Public stringJsondata {Get;Set; } -  -          PublicDateTime CreationDate {Get;Set; } the     } -}

Call the SDK to create the table.

1 Private Async voidcreatetemp ()2 {3     stringDbName =ViewModelLocator.Instance.DBName;4     if(!awaitCommon.checkfileasync (dbName))5     {6Sqlite.sqliteasyncconnection conn =Newsqlite.sqliteasyncconnection (dbName);7         awaitConn. Createtableasync<temp>();8     }9}

Gets the table data.

1 Private AsyncSystem.threading.tasks.task<temp> Gettemp (intID)2 {3Sqlite.sqliteasyncconnection conn =Newsqlite.sqliteasyncconnection (ViewModelLocator.Instance.DBName);4     varquery =awaitConn. Queryasync<temp> ("SELECT * from temp where id=?",New Object[] {ID});5     if(Query! =NULL&& query. Count >0)6     {7         returnquery[0];8     }9     return NULL;Ten}

Add modification data.

1 Private Async voidaddoredittemp (temp temp)2 {3Sqlite.sqliteasyncconnection conn =Newsqlite.sqliteasyncconnection (ViewModelLocator.Instance.DBName);4     varquery =awaitConn. Queryasync<temp> ("SELECT * from temp where id=?",New Object[] {temp. Id});5     if(Query! =NULL&& query. Count >0)6     {7         awaitConn. Updateasync (temp);8     }9     ElseTen     { One         awaitConn. Insertasync (temp); A     } -}

Verify that the database file exists.

1  Public Static Asyncsystem.threading.tasks.task<BOOL> Checkfileasync (stringfileName)2 {3     BOOLFileisexist =true;4     Try5     {6Windows.Storage.StorageFile SF =awaitWindows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync (fileName);7     }8     Catch9     {TenFileisexist =false; One     } A     returnfileisexist; -}

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.