0

I have some data contained in a CSV file, I need to efficiently access that information and want to importing it into my existing database.

I am wondering if I can make a pre-loaded database with the tables I need and then build the rest of the database on top of it (or make a second separate connection), or load the database from the CSV files on first startup.

What would be the preferred method and either way how would can I achieve it efficiently?

p.s 2 files are about 1000 lines long and 2 columns wide which seems to me to be considered fairly small... and the other ones really shouldn't be more then 10 lines long and 6-7 columns wide

Edit: realised I have a bunch of tables that need to be updated yearly, so any form that risks the user input data is unacceptable so using the existing DB is a not an option...

  • Yes, you can import that data into a SQLIte db and include that DB in your project. However, you will have to copy the db file from your project bundle to a writable app folder at startup. There are numerous existing questions that provide detail on how to do this. – Jason Dec 22 '20 at 01:35
  • Hi, thanks for the answer I was trying to find those questions, mind pointing me out in the right direction? – BananaSupreme Dec 22 '20 at 02:00
  • https://stackoverflow.com/questions/48226088/how-to-reference-sqlite-database-that-already-exists-in-xamarin-android – Jason Dec 22 '20 at 02:13
  • That's for Xamarin.Android not forms, and honestly I'm struggling to apply that answer to Forms, is there a cross platform way to copy the database over to the special folder? I understand I have to register some resources on IPhone with Plist is it the same for this one? if so, how do I register a database file? – BananaSupreme Dec 22 '20 at 06:39
  • You copy the .db file into Assets folder,you could also access it in your forms project. – Leo Zhu Dec 22 '20 at 08:46
  • How do I access them? – BananaSupreme Dec 22 '20 at 09:35
  • You could refer to [this](https://stackoverflow.com/questions/42092607/no-such-table-sqlite-when-execute-query-on-xamarin-forms-pcl),using [DependencyService](https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/dependency-service/introduction) to access the Assets folder. – Leo Zhu Dec 25 '20 at 02:00
  • Yes I saw this option, I did find out eventually that xamarin.essentials has filesystem.OpenAppPackageFileAsync which solved part of the problem, I'm still having difficulties but i figured posting onto it seperetly would be better, i think when I solve it all i'll make an answer detailing my full solution for other people to find.. – BananaSupreme Dec 25 '20 at 02:22

0 Answers0