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