I designed a login and registration page using Sqlite database in windows phone 8.1. With the following code I can successfully insert and retrieve the values from sqlite database. But it happens only once. When I restart my emualator I cannot retrieve the values from database.
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();
}
}
}
Aucun commentaire:
Enregistrer un commentaire