在 SQLite Windows Phone 8.1 中创建多个表

Create Multiple Tables in SQLite Windows Phone 8.1

我指的是 Tutorial 将数据存储在 SQLite 数据库中。我正在尝试向名为 "Schools" 的数据库中添加另一个 table。但是它会抛出一个异常,如下所示,说没有这样的 table: Schools.

public class Contacts
{
    //The Id property is marked as the Primary Key
    [SQLite.PrimaryKey, SQLite.AutoIncrement]
    public int Id { get; set; }
    public string Name { get; set; }
    public string Age { get; set; }
    public string Address { get; set; }
    public string School { get; set; }
    public string Gardient { get; set; }
    public string PhoneNumber { get; set; }
    public string Latitude { get; set; }
    public string Longitude { get; set; }
    public string CreationDate { get; set; }
    public Contacts()
    {
        //empty constructor
    }
    public Contacts( string name, string age, string address, string school, string gardient, string phone_no, string latitude, string longitude)
    {

        Name = name;
        Age = age;
        Address = address;
        School = school;
        Gardient = gardient;
        PhoneNumber = phone_no;
        Latitude = latitude;
        Longitude = longitude;
        CreationDate = DateTime.Now.ToString();
    }
}

  public class Schools
    {
        //The Id property is marked as the Primary Key
        [SQLite.PrimaryKey, SQLite.AutoIncrement]
        public int Id { get; set; }
        public string School { get; set; }
        public string Latitude { get; set; }
        public string Longitude { get; set; }
        public string CreationDate { get; set; }
        public Schools()
        {
            //empty constructor
        }
        public Schools( string school,string latitude, string longitude)
        {

            School = school;
            Latitude = latitude;
            Longitude = longitude;
            CreationDate = DateTime.Now.ToString();
        }
    }

DatabaseHelperClass

   public class DatabaseHelperClass
    {
        SQLiteConnection dbConn;

        //Create Tabble 
        public async Task<bool> onCreate(string DB_PATH)
        {
            try
            {
                if (!CheckFileExists(DB_PATH).Result)
                {
                    using (dbConn = new SQLiteConnection(DB_PATH))
                    {
                        dbConn.CreateTable<Schools>();
                        dbConn.CreateTable<Contacts>();

                    }
                }
                return true;
            }
            catch
            {
                return false;
            }
        }

        public void createtable()
        {
            SQLite.SQLiteConnection db = new SQLite.SQLiteConnection(DB_PATH);
            db.CreateTable<Schools>();
            db.CreateTable<Contacts>();
        }

        private async Task<bool> CheckFileExists(string fileName)
        {
            try
            {
                var store = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync(fileName);
                return true;
            }
            catch
            {
                return false;
            }
        }

当我尝试通过文本框向学校 table 输入数据时,抛出此异常。数据输入联系人 table 没有任何问题。我发现了类似的问题,但没有人回答我的问题:(

当应用程序已安装在您的设备上时,您似乎已经创建了 table 或者 emulator.Just 卸载您的应用程序并重新安装 it.It 将 work.This 到期因为所有 table 都是在您首次安装应用程序时创建的 time.Hope 这很有用。