Day 1:学习Windows Phone 使用 SQLite

        private void move(string fn)
        {
            StreamResourceInfo sr = Application.GetResourceStream(new Uri(fn, UriKind.Relative));
            IsolatedStorageFile iStorage = IsolatedStorageFile.GetUserStoreForApplication();
            if (!iStorage.FileExists(fn))
            {
                using (var outputStream = iStorage.OpenFile(fn, FileMode.CreateNew))
                {
                    byte[] buffer = new byte[10000];

                    for (;;)
                    {
                        int read = sr.Stream.Read(buffer, 0, buffer.Length);

                        if (read <= 0)
                            break;

                        outputStream.Write(buffer, 0, read);
                    }
                }
            }
        }

        private void button_Click(object sender, RoutedEventArgs e)
        {
            string fn = "gaokao.sqlite";
            move(fn);
            CSConfig.SetDB(fn);//这句话很重要。设置使用的数据库
            int i = CSDatabase.ExecuteNonQuery("insert into Users (UserName) values ('段二')");//里面是SQl语句
            CSGenericRecordList cslis = CSDatabase.RunQuery("select * from Users");//可以理解为返回一个表格
            string names = "";
            foreach (CSGenericRecord cs in cslis)
            {
                names += "名字:" + cs["UserName"].ToString() + "\n";
            }
            MessageBox.Show(names);
        }

 

转载自:http://www.cnblogs.com/dubaokun/archive/2013/01/09/2852469.html

posted @ 2016-08-24 14:58  段二  阅读(139)  评论(0)    收藏  举报