vendredi 18 septembre 2015

I cannot successfully insert and delete values in sqlite wp8.1

When I launch my application first time the code runs successfully and inserts the value. But when I click on remove button only first time the selected item will be removed. When I add again after deleting one value it is showing an exception

catastrophic failure (exception from hresult: 0x8000ffff (e_unexpected))

Even I cannot delete a value

  protected async override void OnNavigatedTo(NavigationEventArgs e)
    {

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

        var dbpath = ApplicationData.Current.LocalFolder.Path + "/Mydb1.db";
        var con = new SQLiteAsyncConnection(dbpath);

        await con.CreateTableAsync<list>();

        List<list> mylist = await con.QueryAsync<list>("select * from list");
        if (mylist.Count != 0)
        {
            list_view.ItemsSource = mylist;
            list_view.DisplayMemberPath = "list1";
        }
    }


    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);
        try
        {
                list l = new list();
                l.list1 = text_input.Text.ToString();
                list_view.Items.Add(l.list1);
                await con.InsertAsync(l);

                mypop.IsOpen = false;

        }
        catch(Exception ex)
        {

           var MessageDialog = new MessageDialog(ex.Message).ShowAsync();
        }


    }


    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);

        var stt = await con.QueryAsync<list>("delete from list where list1='" + list_view.SelectedItem + "'");


       update();

    }

    public async void update()
    {
        var dbpath = ApplicationData.Current.LocalFolder.Path + "/Mydb1.db";
        var con = new SQLiteAsyncConnection(dbpath);

        List<list> mylist = await con.QueryAsync<list>("select * from list");
        if (mylist.Count != 0)
        {
            list_view.ItemsSource = mylist;
            list_view.DisplayMemberPath = "list1";
        }

    }

    Windows.Storage.ApplicationDataContainer data = Windows.Storage.ApplicationData.Current.LocalSettings;

How to add and delete values also update the values from sqlite wp8.1

(Here list is table and list1 is column)

Aucun commentaire:

Enregistrer un commentaire