How to connect to existing sqlite database

maymaymaymay PHMember

Hi!

I've been struggling to figure out how to connect my xamarin pcl application with my existing sqlite database and display the records upon loading the app. I've researched for possible solutions and I've tried everything that I've seen but still, I wasn't successful in connecting my app with my existing sqlite database. In my existing database, there are 4 records in it. When I tried to display the records in a listview, no records were displayed. I tried to debug my code:

  1. Getting the path of my existing database (in Assets folder): database = new recordsDatabase(DependencyService.Get().GetLocalFilePath("dbTest3.db3"));
  2. Connecting to my existing database: database = new SQLiteAsyncConnection(dbPath); resulted to null.
  3. public Task<List> GetItemsAsync()
    {
    return database.Table().ToListAsync();
    }
    function to retrieve data from my existing database
  4. var list = await App.Database.GetItemsAsync(); to retrieve data from my viewmodel - list count is equal to 0

So far what I've used are the ISQLite and IFileHelper approach. In my trials, I've tried placing my existing database in the Assets folder as well as in the Resources/Raw folder.

Hope you could help me in this. Thank you so much.

Sign In or Register to comment.