The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
Sqlite not finding table RRS feed

  • Question

  • I have this class

    public class home
        {
            public string idMenu { get; set; }
            public string name { get; set; }
            public string image { get; set; }
            public string url { get; set; }
        }

    and i have a class for managing a Database in sqlite that looks like this:

    public class Database
        {
            string dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "db.sqlite");
    
            public Database()
            {
                if (!FileExists("db.sqlite").Result)
                {
                    using (var db = new SQLiteConnection(dbPath))
                    {
                        db.CreateTable<premios>();
                        db.CreateTable<contacts>();
                        db.CreateTable<wines>();
                        db.CreateTable<home>();         
                    }
    
                }
            }
    
    
            private void checkFile(string file)
            {
                IsolatedStorageFile localStorage = IsolatedStorageFile.GetUserStoreForApplication();
                if (localStorage.FileExists(file))
                    Debug.WriteLine("Yes");
                else
                {
                    Debug.WriteLine("Nop");
                }
            }
    
            private async Task<bool> FileExists(string fileName)
            {
                var result = false;
                try
                {
                    var store = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync(fileName);
                    result = true;
                }
                catch
                {
                }
    
                return result;
    
            }
    
    
            public void insertPremio()
            {
                using (var db = new SQLiteConnection(dbPath))
                {
                    db.RunInTransaction(() =>
                    {
                        db.Insert(new premios() {name="lalal",link="https://dl.dropboxusercontent.com/u/14600481/Cartuxa/award1.png"});
                    });
                } 
            }
    
            public void insertHome()
            {
                using (var db = new SQLiteConnection(dbPath))
                {
                    db.RunInTransaction(() =>
                    {
                        home tile1 = new home() { name = "Cartuxa" };
                        home tile2 = new home() { name = "Vinhos" };
                        home tile3 = new home() { name = "Azeites" };
                        home tile4 = new home() { name = "FEA" };
                        home tile5 = new home() { name = "Agentes" };
                        home tile6 = new home() { name = "Contactos" };
    
                        db.Insert(tile1);
                        db.Insert(tile2);
                        db.Insert(tile3);
                        db.Insert(tile4);
                        db.Insert(tile5);
                        db.Insert(tile6);
    
                    });
                }
            }
    
    
            //public void insertWine()
            //{
            //    using (var db = new SQLiteConnection(dbPath))
            //    {
            //        db.RunInTransaction(() =>
            //        {
            //            db.Insert(new wines() { Nome = "Familia1", id = "1", ListaProdutos = null, mId = "1" });
            //        });
            //    }
            //}
    
    
            public void insertContacto()
            {
                using (var db = new SQLiteConnection(dbPath))
                {
                    db.RunInTransaction(() =>
                    {
                        db.Insert(new contacts() { desc = "lalal", idMenu = "2", lat = "48", lon = "8", name = "nhec", page_title = "cont" });
                        db.Insert(new contacts() { desc = "lele", idMenu = "2", lat = "48.1", lon = "8.1", name = "nhoc", page_title = "lala" });
                    });
                }
            }
    
    
            public List<premios> getPremios()
            {
                List<premios> lista = new List<premios>();
                using (var db = new SQLiteConnection(dbPath))
                {
                    var existing = db.Query<premios>("select * from premios");
                    foreach (premios award in existing)
                    {
                        lista.Add(award);
                    }
                }
                return lista;
            }
    
            public List<home> getHome()
            {
                List<home> lista = new List<home>();
                using (var db = new SQLiteConnection(dbPath))
                {
                    var existing = db.Query<home>("select * from home");
                    foreach (home tile in existing)
                    {
                        lista.Add(tile);
                    }
                }
                return lista;
            }
    
            //public List<wines> getWines()
            //{
            //    List<wines> lista = new List<wines>();
            //    using (var db = new SQLiteConnection(dbPath))
            //    {
            //        var existing = db.Query<wines>("select * from wines");
            //        foreach (wines wine in existing)
            //        {
            //            lista.Add(wine);
            //        }
            //    }
            //    return lista;
            //}
    
            public List<contacts> getContacts()
            {
                List<contacts> lista = new List<contacts>();
                using (var db = new SQLiteConnection(dbPath))
                {
                    var existing = db.Query<contacts>("select * from contacts");
                    foreach (contacts cont in existing)
                    {
                        lista.Add(cont);
                    }
                }
                return lista;
            }
        }

    when i try to do operation with the "home" table it says the table doesnt exist, altho i have the 

    db.CreateTable<home>();

    the other tables work well
    what am i missing?

    • Edited by Thought2 Wednesday, February 5, 2014 6:58 PM
    Wednesday, February 5, 2014 6:56 PM

All replies