About Application data(local settings) and Sqlite database in windows phone 8.1

妖精的绣舞 提交于 2019-12-12 00:53:21

问题


I have a small doubt about using SQLite database and local settings. I have an idea about how to use local settings for an app. When we use Application data(local settings) in our application we can restore the previous state of the application. Can we use sqlite local database to store and retrieve the values while we use local settings.

 protected async override void OnNavigatedTo(NavigationEventArgs e)
    {

        if (data.Values["check"] != null)
        {
            this.Frame.Navigate(typeof(BlankPage1));
        }

      if (data.Values["add"] != null)
      {
          list_view.Items.Add(data.Values["add"].ToString());
      }

        if (data.Values["remove"] != null)
        {
            list_view.Items.Remove(data.Values["remove"]);
        }
        var dbpath = ApplicationData.Current.LocalFolder.Path + "/Mydb1.db";
        var con = new SQLiteAsyncConnection(dbpath);

        await con.CreateTableAsync<list>();

    }


    private void Button_Click(object sender, RoutedEventArgs e)
    {
       if(!mypop.IsOpen)
       {
           mypop.IsOpen = true;
       }

    }

    public async void Button_Click_1(object sender, RoutedEventArgs e)
    {
        var dbpath = ApplicationData.Current.LocalFolder.Path + "/Mydb1.db";
        var con = new SQLiteAsyncConnection(dbpath);


        list l = new list();
        data.Values["add"] = l.list1;
        l.list1 = text_input.Text.ToString();
        await con.InsertAsync(l);
        await con.UpdateAllAsync(l.list1);
        data.Values["add"] = l.list1;
        list_view.Items.Add(data.Values["add"].ToString());




      mypop.IsOpen = false;

    }


    private void Button_Click_2(object sender, RoutedEventArgs e)
    {
        if(mypop.IsOpen)
        {
            mypop.IsOpen = false;
        }
    }

    private async void Button_Click_3(object sender, RoutedEventArgs e)
    {
        var dbpath = ApplicationData.Current.LocalFolder.Path + "/Mydb1.db";
        var con = new SQLiteAsyncConnection(dbpath);

        list l = new list();

        data.Values["remove"] = l.list1;

        l.list1 = list_view.SelectedItem.ToString();

        list_view.Items.Remove(list_view.SelectedItem);
        List<list> mylist = await con.QueryAsync<list>("delete from list where list1='" + list_view.SelectedItem + "'");
        mylist.Remove(l);

Please check and verify the code. I can only store single value to local settings. When I restart my application only one value will be shown. It wont show the values inserted in the listview. Please also check delete query. It is not working.. please help me...

来源:https://stackoverflow.com/questions/32635367/about-application-datalocal-settings-and-sqlite-database-in-windows-phone-8-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!