标签:
使用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 }
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 }
标签:
原文地址:http://www.cnblogs.com/includeling/p/4581609.html