Winphone Development Database related Operations summary

Source: Internet
Author: User

1. First of all, WP to. SQLite database operation support, from Google, Baidu, CodePlex. And so on the site to find the following ways;

(1) The oldest to be used by references to third-party Community.CsharpSqlite.WP.dll assemblies (note: If you want to manipulate an existing. SQLite database, instead of creating a data table from scratch, add data ...) And so on, then you need to find this source code on the CodePlex website, make corresponding changes, so as to support the use, otherwise you will encounter very depressed "unable to open the database connection." and other errors)

(2) The second is similar to the first, but its package is different c#- SQLiteWP7.Preview1.Release, this is also on the CodePlex above, the code is similar to the first, but the method has a return DataReader such objects, so that we can do the corresponding data read operation, although the database is copied to the isolated storage root directory, but here The connection string is different, in the following format:

"Version= database version number, Uri=file: Your database Full name" Simple code operation flow:
1 using(Sqliteconnection conn =NewSqliteconnection ("version=3,uri=file:test.db"))2 3 {4 5 Conn. Open ();6 7 using(Sqlitecommand cmd =Conn. CreateCommand ())8 9 {Ten  OneCmd.commandtext ="SQL statements"; A  - cmd. ExecuteNonQuery (); -  the   -  -Cmd. Transaction =Conn. BeginTransaction (); -  + //SQL statement Add parameter -Cmd.commandtext ="INSERT into Test (col, col2, Col3, Col4, Col5) VALUES (@col, @col2, @col3, @col4, @col5); SELECT Last_insert_rowid ();"; +  ACmd. Parameters.Add ("@col",NULL); at  -Cmd. Parameters.Add ("@col2",NULL); -  -Cmd. Parameters.Add ("@col3",NULL); -  -Cmd. Parameters.Add ("@col4",NULL); in  -Cmd. Parameters.Add ("@col5",NULL); to  + cmd.Transaction.Commit (); -  theCmd. Transaction =NULL;
View Code

(3) If you do not want to change Community.CsharpSqlite.WP this source, it is on the internet to find Vici.CoolStorage.WP7 and Vici.Core.WP7 these two assemblies, the personal feeling this way, the code operation is simple, the performance is better than the first kind of slightly;

1 //Note: Add Vici.CoolStorage.WP7.dll and Vici.Core.WP7.dll to the project first2 stringfn ="Mnsecret. DB";//your database name, note the project root directory, and set the build action to resource, not copy3Assembly Assem =assembly.getexecutingassembly ();4             stringAssemeblyname=assem. Fullname.substring (0, Assem. Fullname.indexof (','));5Uri dburi=NewUri ("/"+ Assemeblyname +"; component/"+FN,6 urikind.relative);7             //The program first runs the SQLite database copy to local storage8StreamResourceInfo sr =Application.getresourcestream (Dburi);9IsolatedStorageFile IStorage =isolatedstoragefile.getuserstoreforapplication ();Ten             if(!istorage.fileexists (FN)) One             { A                 using(varOutputStream =istorage.openfile (FN, filemode.createnew)) -                 { -                     byte[] buffer =New byte[10000]; the                      for (; ; ) -                     { -                         intRead = Sr. Stream.read (Buffer,0, buffer. Length); -  +                         if(Read <=0) -                              Break; +  AOutputstream.write (Buffer,0, read); at                     } -                 } -             } -             //connecting to a database - Csconfig.setdb (FN); -             //Data Manipulation inCsgenericrecordlist Cslis = Csdatabase.runquery ("select* from city");//can be understood as returning a table -              foreach(Csgenericrecord CSinchCslis) to              { +                  //fetch every row of data in a table -                  stringresult= cs["data table field name"]. ToString (); the  *}
View Code

About csdatabase inside of the operation method, we can go to http://viciproject.com/wiki/Projects/CoolStorage/WindowsPhone this website to see, may I use a bit of energy loss, Please join us in exploring learning

2. Third-party. SQLite database performance is a bit of a problem, this time need to use the own. SDF database, recommended here vs plug-in SQL Server Compact Toolbox, It can create 3.5 and 4.0 version of the database, note that WP seems to support 3.5, before I used 4.0, the result is tragic, and later still rely on the SQL Server Compact Toolbox re-create 3.5, import data What (suggest a table import data, otherwise vs will die) , we can also create the business object and the data context of the table map with this tool. Let's explore together.

3. Finally, attach a wp7.5 application previously done in the University era: http://www.windowsphone.com/zh-cn/store/app/%E6%81%B6%E9%AD%94%E6%9E%9C%E5%AE%9E%E5% 9b%be%e9%89%b4/9a491e8f-29b4-499b-a24b-81e3484eb404, let's have a lot of spit!!!

(At that time just practicing the database operation technology and the developer to submit the app operation process ...) Personal feeling this app doesn't make much sense)

Http://www.silverlightchina.net/html/zhuantixilie/winphone7/2012/0318/14558.html

Http://www.oschina.net/translate/generate-windows-phone-8-local-database?print

Winphone Development Database related Operations summary

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.