How to deploy a Xamarin app with a prepopulated SQLite database

kc70 · 5K views · 2020 · 12:03

Open on YouTube

Software (other)Databases & storagetutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it as the walkthrough they followed for bundling a ready-made SQLite database in a Xamarin.Forms app, and then come back with follow-up problems like writes not persisting or lists not displaying.

Recommended by 2 people across 2 different months, 2020 to 2023.

What it is

A 12-minute tutorial by kc70 showing how to add a prepopulated SQLite database to the default Xamarin Forms Master-Detail template in Visual Studio. It embeds the database file and copies it out at startup, with the code written once in the shared project for UWP, Android and iOS.

What people said

Recommends Ed_75 · 2020-09 · Stack Overflow · on “How to access a prepopulated SQLite database built into a Xamarin.forms app?”

--> It's a partial solution, for now writing to the database is not working. I found a video that precisely answers this question, by kc70: [this video] . Here is a summary of it in 10 steps: 1- Create a Xamarin Mobile app 2- Choose Master Detail, with UWP 3- Add SQLite-net-pcl to the shared project 4- In Models/Item.cs - Add Using SQLite; - Change string id to int - Change the references to that too in Services/MockDataStore.cs and Services/IDataStore.cs 5- New folder Data 6- New RestaurantDatabase Class in Data: using SQlite; public class RestaurantDatabase { static SQLiteAsyncConnection Database; public Restaurant() { string DatabasePath = Path.Combine(Environment.GetFolderPath(Environment.Spe

Recommends Molnar Istvan · 2020-12 · Stack Overflow · on “My Xamarin project not displaying values in ListView”

I'm starting to learn Xamarin. I followed this video course: [this video] . I have an SQLite database populated, that i added (in root) in the code project as embedded resource. If I check ItemPage.xaml, there is a black windows and i don't see any listview. (This is a Master-Detail project with .net standard). I checked with the debugger, the ExecuteLoadItemsCommand gets the rows from the db, but the listview didn't display it. ItemsPage.xaml: <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns=" [LINK] " xmlns:sfgrid="clr-namespace:Syncfusion.SfDataGrid.XForms;assembly=Syncfusion.SfDataGrid.XForms" xmlns:x=" [LINK] " xmlns:local="clr-namespace:SampleBrowser.SfDataGrid;assembly=SampleBrow

Cites paulywalnuts01212 · 2020-10 · Stack Overflow · on “Writing to Xamarin Pre-populated Database”

I followed this tutorial to set up a pre-populated database for my mobile app: [this video] It works as intended and I'm now able to pull and display data from the database that I've added to my project as an embedded resource. The only issue is I'm unable to write to the database. Whenever I do an insert or update to one of the tables the database doesn't store the new data. How can I fix this? public App() { InitializeComponent(); string dbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "myDatabase.db3"); Assembly assembly = IntrospectionExtensions.GetTypeInfo(typeof(App)).Assembly; Stream embeddedDbStream = assembly.GetManifestResourceStream("MyAp

Cites vytaute · 2023-03 · Stack Overflow · on “Unable to get correct path with Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) method in Xamarin”

In Xamarin C# app I am trying to reach my database file (and find where it is located) using this code: string dbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "patients.db"); dbPath become equal to "/data/user/0/com.companyname.MobileApp/files/.local/share" which is nonsense because in tutorial it shows that path should be something like "C://Users//......" What am I missing? Maybe I need to set any environment variables in order to use this method? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) I was following this tutorial: [this video] And I am using Visual Studio and simulating Android device.