locked
read sqlite database

    Question

  • Hi

    I imported from excel a sqlite database

    Now the problem is that I don't know how to obtain the data of the table to display in a listview.

    Please see where the database (plantasmedicinais1) is (on the right list of the app, this might be the problem...) and my code.

    Wednesday, April 8, 2015 5:25 AM

Answers

  • 1) In Visual Studio, you could set the "plantasmedicinais1.sqlite" file "Copy to Output Directory" to "Copy always" to ensure the file is copied to the app installation folder. Once this is done, you can then  copy the file to your application local folder.

    Example:

    var myDBPath = Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, @"plantasmedicinais1.sqlite");
    var dbFile = await StorageFile.GetFileFromPathAsync(myDBPath);
    await dbFile.CopyAsync(Windows.Storage.ApplicationData.Current.LocalFolder);

    After copying the file to your localfolder path, you can make the calls just like you are doing in your original code.

    Hope this helps.


    Abdulwahab Suleiman


    Wednesday, April 8, 2015 9:46 PM
    Moderator

All replies

  • 1) In Visual Studio, you could set the "plantasmedicinais1.sqlite" file "Copy to Output Directory" to "Copy always" to ensure the file is copied to the app installation folder. Once this is done, you can then  copy the file to your application local folder.

    Example:

    var myDBPath = Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, @"plantasmedicinais1.sqlite");
    var dbFile = await StorageFile.GetFileFromPathAsync(myDBPath);
    await dbFile.CopyAsync(Windows.Storage.ApplicationData.Current.LocalFolder);

    After copying the file to your localfolder path, you can make the calls just like you are doing in your original code.

    Hope this helps.


    Abdulwahab Suleiman


    Wednesday, April 8, 2015 9:46 PM
    Moderator
  • Thanks Abdulwahab

    I understood and everything is ok except that I do not understand what is this StorageFile

    My systems complains that it does not exist in the current context.

    I suppose it is a new location where my app can access the database...

    How can you define it and what is the assembly resource?

    I'm doing this inside App.xaml.cs

    Wednesday, April 8, 2015 10:05 PM
  • I solved this problem with:

    using Windows.Storage;

    it was simple but I get the following error and I never get the values at the list view...

    And if I comment this line I get the values at list view.

    So the question now is how to test before if the file is already created.

    This is a very specific context and I can't understand this small issue...



    Wednesday, April 8, 2015 11:20 PM
  • I tried the following but I got the error at the bottom:

    Wednesday, April 8, 2015 11:28 PM
  • I was able now to solve the problem!

    Thanks

    Wednesday, April 8, 2015 11:42 PM