Wp7 databases are a headache because they currently do not support databases. Of course, you can also use Microsoft's paid Database, cloud, or independent storage, if you want to design a data management software, the database is essential. Next I will introduce the Sqlite Client for Windows Phone database. If you are unfamiliar with this database, first look at this SQLite introduction.
I chose this database because I am familiar with SQL statements and have operated C # To connect SQL statements. If so, I should be familiar with the following statements.
The following describes how to use my secret protection service:
Before applying SQLite, add two references.
Community. CsharpSqlite. WP7
SqlLiteClient. WP7
Then add a namespace: using Community. CsharpSqlite. SQLiteClient;
The following is the code:
Open (create) A database:
Private SqliteConnection co = null;
Co = new SqliteConnection ();
Co. ConnectionString = "Version = 3, uri = file: mydb. sqlite ";
Co. Open ();
Table creation:
SqliteCommand cm = co. CreateCommand ();
Cm. CommandText = "create table user (u_min text, lei integer, u_name text, u_mima text, u_bei text )";
Cm. ExecuteNonQuery ();
Add data:
SqliteCommand cm = co. CreateCommand ();
Cm. CommandText = "insert into user values (@ u_min, @ lei, @ u_name, @ u_mima, @ u_bei )";
Cm. Parameters. Add ("@ u_min", null );
Cm. Parameters ["@ u_min"]. Value = textBox1.Text;
Cm. Parameters. Add ("@ lei", null );
Cm. Parameters ["@ lei"]. Value = textBox1.Text;
Cm. Parameters. Add ("@ u_name", null );
Cm. Parameters ["@ u_name"]. Value = textBox2.Text;
Cm. Parameters. Add ("@ u_mima", null );
Cm. Parameters ["@ u_mima"]. Value = passwordBox1.Password;
Cm. Parameters. Add ("@ u_bei", null );
Cm. Parameters ["@ u_bei"]. Value = textBox3.Text;
Cm. ExecuteNonQuery ();
Search data:
Public SqliteDataReader re = null;
SqliteCommand cm = co. CreateCommand ();
Cm. CommandText = "select * from user where lei";
Re = cm. ExecuteReader ();
Re. Read ();
TextBox3.Text = re ["u_min"]. ToString ();
The deletion and update operations are similar to the following:
SqliteCommand cm = co. CreateCommand ();
Cm. commandText = "update user set u_min = @ min, lei = @ lei, u_name = @ name, u_mima = @ mima, u_bei = @ bei where u_mima = '"+ mima + "'";
Cm. Parameters. Add ("@ min", null );
Cm. Parameters ["@ min"]. Value = textBoxmin. Text;
Cm. Parameters. Add ("@ lei", null );
Cm. Parameters ["@ lei"]. Value = no;
Cm. Parameters. Add ("@ name", null );
Cm. Parameters ["@ name"]. Value = textBoxname. Text;
Cm. Parameters. Add ("@ mima", null );
Cm. Parameters ["@ mima"]. Value = textBoxmima. Text;
Cm. Parameters. Add ("@ bei", null );
Cm. Parameters ["@ bei"]. Value = textBoxbei. Text;
Cm. ExecuteNonQuery ();
It should be particularly noted that, if you want to connect the query condition (where = "") in the SQL statement, the query condition in it cannot be Chinese characters, otherwise it will not be found
If you read the above Code carefully, you will find that using Sqlite Client for Windows Phone is still very simple, but there are few resources on the Internet.
It's all about that article: Sqlite programming skills for Microsoft WP7 local database; and I 've tried it as per the article, but it's useless, and it's still a big bend, so I wrote this article, I hope you don't want
Detour .... I wrote my blog for the first time, and it took a long time to contact WP7. If you have any questions, try to answer them.
Http://blog.csdn.net/wp_lijin/article/details/7370790