1

I have created SQLite database and have copied it in the root of the project like that:

enter image description here

The database is called MobileSell.db It appears in Visual Studio like that:

enter image description here

My question is how can I reference it so afterwards I can say connection.InsertIntoTableArticles(value)(this is pseudo code)

Profile2ForStack
  • 473
  • 2
  • 8
  • 16

1 Answers1

1

You can refer to this.

There only three steps to achieve it:

1) Create Assets folder which is parallel with Resources folder in your project, put your .db file into it.

2) Copy the .db file to SDCard when first open the app;

3) Use SQLite.SQLiteConnection(path) to open your .db and query it.

Robbit
  • 4,300
  • 1
  • 13
  • 29
  • Could you give more details on point 2) Copy the .db file to SDCard when first open the app? – Profile2ForStack Jan 15 '18 at 10:00
  • Please use [BinaryReader](https://msdn.microsoft.com/zh-cn/library/system.io.binaryreader(v=vs.110).aspx) to read from your `.db` file and use [BinaryWriter](https://msdn.microsoft.com/en-us/library/system.io.binarywriter(v=vs.110).aspx) to write to you sdcard. In Android, you can't open .db from `Assets` or `raw` directly, so you need copy it to other folder, and this `SQLite.SQLiteConnection(path)` can open any folder. – Robbit Jan 15 '18 at 10:27
  • Instead of copying .db to SDCard, could I copy the .db file into the apk folder of the app and then reference it from there like that: SQLite.SQLiteConnection(path-to-apk-folder)? – Profile2ForStack Jan 15 '18 at 10:32
  • Yes, like `/data/data/package name/test.db` – Robbit Jan 15 '18 at 10:35