我在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/