SQLite is a lightweight, fast, and open-source embedded database. Its official homepage is http://www.sqlite.org/index.html, attracting many developers. It has branches in various technical camps and has won the favor of some it giants. It is a powerful tool for rapid development. Especially in the mobile field, SQLite has more and more obvious advantages. In Symbian, Android, and even iPhone, SQLite can run perfectly, but Windows Phone 7 lacks support for local databases. The latest version of Windows Phone 7 is 2010 million l refresh. It is depressing to use a temporary storage area, XML, or cloud to access data. SQL Ce 4 was released two days ago and supports ASP. NET. I hope it will be used in Windows Phone 7 in the future.
Despite lack of official support, some people outside China have rewrittenC # SQLiteTo run on Windows Phone 7.HereView. (You need to jump over the wall) I tested it. It's not bad. It's a small problem. In addition, all operations in the temporary storage area are released on codeplex.Windows Phone 7 DBProject, supports no-SQL operations, very good, interested friends can try. Here we will try to operate SQLite on Windows Phone 7.
TestCodeDownload
Test environment:
Windows Server 2008 r2 datacenter
Visual Studio 2010 ultimate
Windows Phone 7 develop tools 2010 release L refresh
C # SQLite WP
1. Create a Silverlight for Windows Phone project:
2. Add a reference to C # SQLite WP:
3. Place the following controls: (because Windows Phone 7 currently does not support Chinese characters, all are in English. Please forgive me)
4. The test is simple. Click adduser and add the user input to the database:
Code
Private String _ Strdb = @" Test. db3 " ;
Private Void FN add user ()
{
String MSG = String . Empty;
Sqlite3.sqlite3 DB = New Sqlite3.sqlite3 ();
Int RC = Sqlite3.sqlite3 _ open ( This . _ Strdb, Ref DB );
If (RC = Sqlite3.sqlite _ OK)
{
String Sql1 = @" Create Table users
(
Username varchar (20) primary key,
Userpass varchar (50 ),
Email varchar (50)
) " ;
Sqlite3.sqlite3 _ exec (dB, sql1, (sqlite3.dxcallback) This . Callback, Null , Ref MSG );
String Sql2 = @" Insert into users (username, userpass, email)
Values (' " + This . Txtusername. Text + @" ',' " + This . Txtuserpass. Password + @" ',' " + This . Txtemail. Text + @" ') " ;
Int Result = Sqlite3.sqlite3 _ exec (dB, sql2, (sqlite3.dxcallback) This . Callback, Null , Ref MSG );
If (Result = Sqlite3.sqlite _ OK)
{
System. Windows. MessageBox. Show ( " Success! " , " Add User " , Messageboxbutton. OK );
}
Else
{
System. Windows. MessageBox. Show ( " Error! " , " Add User " , Messageboxbutton. OK );
}
}
}
I have not found a method to create a database using an absolute path or to open an existing database. If you have any idea, please give me some advice.
It is a little difficult to enter the password here. Due to the delay, the character of the password is displayed first and then becomes "*".
This project only performs basic non-empty verification for testing purposes.
5. Summary
Although Windows Phone 7 does not support local databases well now, it will certainly improve after the official version is released due to its important position in Microsoft's mobile strategy. It may be SQL Ce 4, or a new local database, there will be a third-party solution. Currently, Windows Phone 7 UI controls are a little lacking, even the gridview does not exist. I hope it can be improved. The code for this test is very simple, mainly related operations in SQLite. You can get started by taking a look at the sample documentation. SQLite functions are far from the same, so interested friends can explore it in depth.