码迷,mamicode.com
首页 > 数据库 > 详细

Windows Phone 九、SQLite数据库

时间:2015-06-16 22:28:54      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:

使用SQLite数据库

安装 SQLite for Windows Phone 8.1 插件
新建 Windows Phone 8.1 项目
添加 SQLite for Windows Phone 8.1 引用
由于该组件依赖于 Microsoft Visual C++ 2013 Runtime Package for Windows Phone,所以同时引用 Microsoft Visual C++ 2013 Runtime Package for Windows Phone
右键管理 Nuget 包引用
搜索 sqlite-net 并安装

 

技术分享
1     public class Person
2     {
3         [PrimaryKey, AutoIncrement]
4         public int Id { get; set; }
5         [MaxLength(8)]
6         public string Name { get; set; }
7         public int Age { get; set; }
8         public char Gender { get; set; }
9     }
Person
 1         private void Button_Click(object sender, RoutedEventArgs e)
 2         {
 3             //创建数据库(不存在情况创建,存在则打开)
 4             var connection = new SQLiteConnection("temp.db");
 5             //创建表
 6             connection.CreateTable<Person>();
 7             Person zhang = new Person();
 8             //zhang.Id = 1;
 9             zhang.Name = "letter zhang";
10             zhang.Age = 18;
11             zhang.Gender = ;
12             //添加数据
13             var result = connection.Insert(zhang);//返回执行结果受影响行数
14             System.Diagnostics.Debug.WriteLine(result);
15             //更新操作
16             result = connection.Update(new Person { Id = 2, Name = "zhangsan", Age = 19 });
17             System.Diagnostics.Debug.WriteLine(result);
18             //读取数据
19             var temp = connection.Find<Person>(1);
20             System.Diagnostics.Debug.WriteLine(temp.Name);
21             //读取全部数据
22             var list = connection.Query<Person>("select * from Person where id>=?", 1);
23             foreach (var item in list)
24             {
25                 System.Diagnostics.Debug.WriteLine(item.Name);
26             }
27             //删除操作
28             connection.Delete<Person>(1);
29         }

 

Windows Phone 九、SQLite数据库

标签:

原文地址:http://www.cnblogs.com/includeling/p/4581609.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!