时间:2021-07-01 10:21:17 帮助过:2人阅读
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数据库
标签: