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

标签 c# sqlite visual-studio-2013 windows-phone-8.1

我在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();
        }
    }
}

最佳答案

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

这不会发生在实际的物理设备上。

关于c# - 当我重新启动我的模拟器时,我无法在 sqlite Windows Phone 8.1 中检索数据库值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32884652/

相关文章:

iphone - iOS简单的SQL错误

c - 在 64 位 Windows 上从 CMD 调用 cl (Visual Studio 2013) 交叉编译器

c# - "URI formats are not supported."异常刚刚开始出现在非常旧的、未更改的代码中

C#:在网格中显示数据的最佳方式?

c# - 为什么 resharper 建议只读字段

c# - 非顶级表单的 StartPosition

c# - 如何在 c# 的 ms word 文档中设置文本方向 RightToLeft?

iphone - iOS 应用程序上的 SQLite DB 是否限制为任意大小

database - 空sqlite数据库的BASH列表头

c# - 使用 Visual Studio 在代码中查找可等待的方法