Reputation: 145
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)
Upvotes: 1
Views: 390
Reputation: 145
This catastrophic failure is many because of adding list items in two ways in the above code. So just insert the values to the textbox and assign it to list. To insert a list of items to the database follow the below step
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;
await con.InsertAsync(l);
update();
public async void update()
{
var dbpath = ApplicationData.Current.LocalFolder.Path + "/Mydb1.db";
var con = new SQLiteAsyncConnection(dbpath);
list_view.ItemsSource = new List<list>();
List<list> mylist = await con.QueryAsync<list>("select * from list");
if (mylist.Count != 0)
{
list_view.ItemsSource = mylist;
list_view.DisplayMemberPath = "list1";
}
We can also delete the same values with the simple code
private async void Button_Click_3(object sender, RoutedEventArgs e)
{
var dbpath = ApplicationData.Current.LocalFolder.Path + "/Mydb1.db";
var con = new SQLiteAsyncConnection(dbpath);
if (list_view.SelectedItem != null)
{
list k = (list)list_view.SelectedItem;
await con.QueryAsync<list>("delete from list where list1='" + k.list1 + "'");
update();}
So selected item can be deleted from the list (Here list is the class name and list1 is the column name)
Upvotes: 1