zoukankan      html  css  js  c++  java
  • win8 应用商店程序使用SQLITE数据库

    http://www.cnblogs.com/zhuzhenyu/archive/2012/11/27/2790193.html

    using SQLite;
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Runtime.InteropServices.WindowsRuntime;
    using Windows.Foundation;
    using Windows.Foundation.Collections;
    using Windows.UI.Xaml;
    using Windows.UI.Xaml.Controls;
    using Windows.UI.Xaml.Controls.Primitives;
    using Windows.UI.Xaml.Data;
    using Windows.UI.Xaml.Input;
    using Windows.UI.Xaml.Media;
    using Windows.UI.Xaml.Navigation;
    
    // “空白页”项模板在 http://go.microsoft.com/fwlink/?LinkId=234238 上有介绍
    
    namespace beelinechinese
    {
        /// <summary>
        /// 可用于自身或导航至 Frame 内部的空白页。
        /// </summary>
        public sealed partial class sqldemo : Page
        {
            public sqldemo()
            {
                this.InitializeComponent();
            }
            
            private void Button_Click(object sender, RoutedEventArgs e)
            {
                using (var db = CreateSQLiteConnection())
                {
    
                    //创建表
    
                    db.CreateTable<Person>();
    
    
    
                }
            }
    
            private SQLiteConnection CreateSQLiteConnection()
            {
    
                //数据文件保存的位置
    
                var dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "db3.sqlite");
    
                //打开创建数据库和表
    
              return new SQLite.SQLiteConnection(dbPath);
                }
       
            private void dgfgf_Click(object sender, RoutedEventArgs e)
            {
              
                var db =CreateSQLiteConnection();
    
            
                //单条插入语句
    
                db.Insert(new Person() { ID=System.Guid.NewGuid().ToString(), FirstName = "liufei", LastName = "Sky" });
                db.Close();
            }
    
            private void Button_Click_1(object sender, RoutedEventArgs e)
            {
                var db = CreateSQLiteConnection();
                List<object> list = db.Query(new TableMapping(typeof(Person)), "select *  from  Person");
                db.Close();
                List<Person> ml = list.Cast<Person>().ToList();
                txtmsg.Text = ml[0].FirstName;
            }
    
            private void Button_Click_2(object sender, RoutedEventArgs e)
            {
                try
                {
                    var db = CreateSQLiteConnection();
               //     db.Delete<Person>(new Person() { FirstName = "lisa" });
    
                    SQLiteCommand cmd = db.CreateCommand("delete from  person where FirstName = 'lisa'");
    
                    cmd.ExecuteNonQuery();
                  db.Close(); }
                catch (Exception ex)
                {
                    txtmsg.Text = ex.ToString();
                }
              
            }
    
            private void Button_Click_3(object sender, RoutedEventArgs e)
            {
                var db = CreateSQLiteConnection();
                SQLiteCommand cmd = db.CreateCommand("update person set FirstName='lisa'where FirstName='liufei'");
    
                cmd.ExecuteNonQuery();
                db.Close();
            }
        }
    
      public  class Person
        {
    
            [SQLite.PrimaryKey]
    
            public string ID { get; set; }
    
            public string FirstName { get; set; }
    
            public string LastName { get; set; }
            public DateTime LastLogin { get; set; }
    
            public string NickName { get; set; }
    
            public bool ShowPic { get; set; }
    
    
        }
    }
    using SQLite;
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Runtime.InteropServices.WindowsRuntime;
    using Windows.Foundation;
    using Windows.Foundation.Collections;
    using Windows.UI.Xaml;
    using Windows.UI.Xaml.Controls;
    using Windows.UI.Xaml.Controls.Primitives;
    using Windows.UI.Xaml.Data;
    using Windows.UI.Xaml.Input;
    using Windows.UI.Xaml.Media;
    using Windows.UI.Xaml.Navigation;
    
    // “空白页”项模板在 http://go.microsoft.com/fwlink/?LinkId=234238 上有介绍
    
    namespace beelinechinese
    {
        /// <summary>
        /// 可用于自身或导航至 Frame 内部的空白页。
        /// </summary>
        public sealed partial class sqldemo : Page
        {
            public sqldemo()
            {
                this.InitializeComponent();
            }
            
            private void Button_Click(object sender, RoutedEventArgs e)
            {
                using (var db = CreateSQLiteConnection())
                {
    
                    //创建表
    
                    db.CreateTable<Person>();
    
    
    
                }
            }
    
            private SQLiteConnection CreateSQLiteConnection()
            {
    
                //数据文件保存的位置
    
                var dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "db3.sqlite");
    
                //打开创建数据库和表
    
              return new SQLite.SQLiteConnection(dbPath);
                }
       
            private void dgfgf_Click(object sender, RoutedEventArgs e)
            {
              
                var db =CreateSQLiteConnection();
    
            
                //单条插入语句
    
                db.Insert(new Person() { ID=System.Guid.NewGuid().ToString(), FirstName = "liufei", LastName = "Sky" });
                db.Close();
            }
    
            private void Button_Click_1(object sender, RoutedEventArgs e)
            {
                var db = CreateSQLiteConnection();
                List<object> list = db.Query(new TableMapping(typeof(Person)), "select *  from  Person");
                db.Close();
                List<Person> ml = list.Cast<Person>().ToList();
                txtmsg.Text = ml[0].FirstName;
            }
    
            private void Button_Click_2(object sender, RoutedEventArgs e)
            {
                try
                {
                    var db = CreateSQLiteConnection();
               //     db.Delete<Person>(new Person() { FirstName = "lisa" });
    
                    SQLiteCommand cmd = db.CreateCommand("delete from  person where FirstName = 'lisa'");
    
                    cmd.ExecuteNonQuery();
                  db.Close(); }
                catch (Exception ex)
                {
                    txtmsg.Text = ex.ToString();
                }
              
            }
    
            private void Button_Click_3(object sender, RoutedEventArgs e)
            {
                var db = CreateSQLiteConnection();
                SQLiteCommand cmd = db.CreateCommand("update person set FirstName='lisa'where FirstName='liufei'");
    
                cmd.ExecuteNonQuery();
                db.Close();
            }
        }
    
      public  class Person
        {
    
            [SQLite.PrimaryKey]
    
            public string ID { get; set; }
    
            public string FirstName { get; set; }
    
            public string LastName { get; set; }
            public DateTime LastLogin { get; set; }
    
            public string NickName { get; set; }
    
            public bool ShowPic { get; set; }
    
    
        }
    }
  • 相关阅读:
    【ecshop】 完全清除版权信息
    【ecshop】使用sql 清除测试数据
    Java异常处理:给程序罩一层保险
    想清楚你究竟想成为什么样的人了吗?
    Java集合类的那点通俗的认知
    2019年的第一天,我给自己定了一份读书计划
    Java的内部类真的那么难以理解?
    29岁了还一事无成是人生的常态?
    Java接口的实例应用:致敬我的偶像——何塞·穆里尼奥
    程序员年底众生相
  • 原文地址:https://www.cnblogs.com/lyl6796910/p/4662931.html
Copyright © 2011-2022 走看看