嗨,我正在使用Windows Phone 8應用程序。我想設置現有的用戶登錄,我可以添加用戶註冊,但我不能做用戶登錄我的代碼如下。如何設置用戶登錄Windows Phone 8使用sqlite數據庫?
public partial class LoginPage : PhoneApplicationPage
{
public LoginPage()
{
InitializeComponent();
}
public static class dal
{
public static SQLiteAsyncConnection connection;
public static bool isDatabaseExisting;
public static async void ConnectToDB()
{
try
{
StorageFile storageFile = await ApplicationData.Current.LocalFolder.GetFileAsync("Bestin.sqlite");
isDatabaseExisting = true;
}
catch (Exception ex)
{
isDatabaseExisting = false;
}
if (!isDatabaseExisting)
{
try
{
StorageFile databaseFile = await Package.Current.InstalledLocation.GetFileAsync("Bestin.sqlite");
await databaseFile.CopyAsync(ApplicationData.Current.LocalFolder);
isDatabaseExisting = true;
}
catch (Exception ex)
{
isDatabaseExisting = false;
}
}
if (isDatabaseExisting)
{
connection = new SQLiteAsyncConnection(Path.Combine(ApplicationData.Current.LocalFolder.Path, "Bestin.sqlite"), true);
}
}
}
private void Click_Login(object sender, RoutedEventArgs e)
{
dal.ConnectToDB();
var query = dal.connection.QueryAsync<Task>("SELECT * FROM Task Where Email=" + "\'" + txtEmailaddress.Text + "\'" + "and Password=" + "\'" + txtPassword.Password + "\'").Result;
if (query == null)
{
// invalid Login credentials
}
else
{
// do login
}
}
}
我使用你的code.I遇到錯誤該系統找不到指定的文件。 (異常來自HRESULT:0x80070002)
試試這個,讓我知道羯羊它的工作或不... –
我使用你的代碼,我得到錯誤:'isDatabaseExisting'這個名字在當前上下文中不存在。這唯一的錯誤 – raja
我已經更新了我的解決方案請添加公共靜態布爾isDatabaseExisting;就在公共靜態SQLiteAsyncConnection連接下方; –