找不到表 - SQLITE错误

时间:2016-11-24 09:41:13

标签: sql sqlite

我正在开发Windows Phone 8应用程序。

我的sqlite prepare语句有些困难。我得到一个错误,说我的桌子不存在,虽然我已经在多个地方检查了它,但它确实存在。 它确实有效,直到我向SQLite数据库添加了一些新表,现在它只是不识别任何表 - 所以我很困惑!

ERROR Message

Database

Code

我也试过硬编码完整路径..例如C:\ App \ datbase.db等

代码:

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.IO.IsolatedStorage;
using SQLitePCL;



namespace WP7.VideoScanZXing.SampleApp
{
    public partial class Page1 : PhoneApplicationPage
    {

        string connLOCDAT = "Data Source =\\Resources\\DB\\MCRS_Data.sdf;Persist Security Info=False";
        string connLOCLUDAT = "Data Source =\\Resources\\DB\\MCRSLU_MYCUBE.sdf;Persist Security Info=False";

        public Page1()
        {
            InitializeComponent();

            //check the isolated storage to see if the user has saved a username and password.
            CheckIsoStore();


        }

        public void CheckIsoStore() {


            if (IsolatedStorageSettings.ApplicationSettings.Contains("UsrEmail"))
            {
                    //The user has saved details
                    //populate the email and password box automatically
                    //Dont forget to check the save details box too

                    tbEmail.Text = IsolatedStorageSettings.ApplicationSettings["UsrEmail"].ToString();
                    pbPassword.Password = IsolatedStorageSettings.ApplicationSettings["UsrPassword"].ToString();
                    cbSaveDetails.IsChecked = true;
            }
        }

        public void failedLogin()
        {
            MessageBox.Show("Error:  Email or Password are incorrect.  Please try again.");
            tbEmail.Focus();

        }


        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {


                //validate user

            string strEmail = tbEmail.Text;
            string strPassword = pbPassword.Password.ToString();

            //bool bolValidUser = false;
            //validate username and password here!




            if (bolValidUser(strEmail, strPassword) == true)
            {
                //user has been validated and can continue.

                if (cbSaveDetails.IsChecked == true)
                {
                    //save the users details here

                    IsolatedStorageSettings.ApplicationSettings["UsrEmail"] = strEmail;
                    IsolatedStorageSettings.ApplicationSettings["UsrPassword"] = strPassword;
                    IsolatedStorageSettings.ApplicationSettings.Save();

                }
                else {

                    IsolatedStorageSettings.ApplicationSettings.Remove("UsrEmail");
                    IsolatedStorageSettings.ApplicationSettings.Remove("UsrPassword");

                    IsolatedStorageSettings.ApplicationSettings.Save();


                }


                NavigationService.Navigate(new Uri("/MenuPage.xaml", UriKind.Relative));


            }
            else {
                //redirect the user back to the home screen with a message
               //NavigationService.Navigate(new Uri("/LoginPage.xaml?message=Login error ", UriKind.Relative));
                failedLogin();
            }

        }


        public static SQLiteConnection dbConn;

        public bool bolValidUser(string Uname, string PWord)
        {




            dbConn = new SQLitePCL.SQLiteConnection(Windows.ApplicationModel.Package.Current.InstalledLocation.Path + @"\bizData.db", SQLiteOpen.READWRITE);
            {
                //StorageFile databaseFile = await .GetFileAsync("bizData.db");
                //await databaseFile.CopyAsync(ApplicationData.Current.LocalFolder);
            }


                //using (var statement = dbConn.Prepare(@"SELECT * FROM [MCRS_LU_Login] WHERE [Email] = " + Uname + " AND [Password] = " + PWord))
                using (var statement = dbConn.Prepare(@"SELECT * FROM [BARCODES]"))
            {
                if (statement.Step() == SQLiteResult.ROW)
                {
                    //new MessageDialog(Convert.ToString(statement.DataCount)).ShowAsync();
                    //if ()
                    string strLinkedUser;
                    strLinkedUser = statement[3].ToString();

                    IsolatedStorageSettings.ApplicationSettings["UsrADName"] = statement[0].ToString();
                    return true;

                }
                else
                {

                    return false;
                    //await msgDialog.ShowAsync();
                }

            }

        }

        private void tbEmail_GotFocus(object sender, RoutedEventArgs e)
        {
            imgMail.Visibility =  Visibility.Collapsed;
        }

        private void tbEmail_LostFocus(object sender, RoutedEventArgs e)
        {
            if(tbEmail.Text =="") {
                imgMail.Visibility = Visibility.Visible;
            }
        }

        private void pbPassword_LostFocus(object sender, RoutedEventArgs e)
        {
            if (pbPassword.Password == "")
            {
                imgPassword.Visibility = Visibility.Visible;
            }
        }

        private void pbPassword_GotFocus(object sender, RoutedEventArgs e)
        {
            imgPassword.Visibility = Visibility.Collapsed;
        }
    }

}

0 个答案:

没有答案