当我重新启动模拟器时,我无法在sqlite Windows phone 8.1中检索数据库值

本文关键字:phone 检索 数据库 Windows 模拟器 重新启动 sqlite | 更新日期: 2023-09-27 18:15:41

我在windows phone 8.1中使用Sqlite数据库设计了一个登录注册页面。使用下面的代码,我可以成功地从sqlite数据库插入和检索值。但这种情况只会发生一次。当我重新启动仿真器时,我无法从数据库中检索值。

 protected async override void OnNavigatedTo(NavigationEventArgs e)
    {
        var dbpath = ApplicationData.Current.LocalFolder.Path + "/ebook.db";
        var con = new SQLiteAsyncConnection(dbpath);
        await con.CreateTableAsync<Register>();
    }
    private async void Button_Click(object sender, RoutedEventArgs e)
    {
        var dbpath = ApplicationData.Current.LocalFolder.Path + "/ebook.db";
        var con = new SQLiteAsyncConnection(dbpath);
        await con.CreateTableAsync<Register>();
        Register m = new Register();
        m.Name = text_reg.Text;
        m.Password = text_password.Password;
        string rd = "";
        if (radio_male.IsChecked == true)
        {
            rd = "Male";
        }
        else
        {
            rd = "Female";
        }
        m.Gender = rd;
        m.State = ((ComboBoxItem)combo_box.SelectedItem).Content.ToString();

        await con.InsertAsync(m);
        MessageDialog md = new MessageDialog("success");
        await md.ShowAsync();
    }
    private async void Button_Click_1(object sender, RoutedEventArgs e)
    {
        var dbpath = ApplicationData.Current.LocalFolder.Path + "/ebook.db";
        var con = new SQLiteAsyncConnection(dbpath);
        Register t = new Register();
        string query = string.Format("select Name,Password from Register where Name='{0}' and Password='{1}'", text_user.Text, text_pass.Password);
        List<Register> mylist = await con.QueryAsync<Register>(query);
        if (mylist.Count == 1)
        {
            t = mylist[0];
        }
        if (t.Name == text_user.Text && t.Password == text_pass.Password)
        {
            this.Frame.Navigate(typeof(MainPage));
        }
        else
        {
            var messagedialog = new MessageDialog("Unsuccessful").ShowAsync();
        }
    }
}

当我重新启动模拟器时,我无法在sqlite Windows phone 8.1中检索数据库值

这是预期的行为。状态在Windows Phone模拟器中没有持久化。当您重新启动它时,它会丢失您之前存储的所有数据(设置,安装的应用程序以及您在存储上写入的任何内容)。