Xamarin PCL Database Sample Code

1.) Download the Xamarin PCL Database Sample Code (Visual Studio 2015):

Download link.

2.) This sample code is a Xamarin project implementation of SQLite database using C# for using the the following library:

SQLite.Net-PCL by oystein krog, Frank Krueger, Tim Heuer

SQLite.NET-PCL is an open source, minimal library to allow .NET and Mono applications to store data in SQLite databases.

It is a fork of the original sqlite-net project, which aims to cleanup/improve the code and deliver the package as PCL assemblies with some additional platform-specific implementations.


3.) The source code was created using Visual Studio 2015.

If you do not have a Visual Studio 2015 or higher version, proceed to download Visual Studio 2017 community edition.

https://www.visualstudio.com/vs/express/

4.) This sample code was created using the following references:
5.) The sample code only targets Android platform.


6.) Project specifications:

6.1) Visual Studio project:
  • Templates --> Visual C# --> Cross-Platform --> Cross Platform App (Xamarin)
  • UI Technology --> Xamarin.Forms
  • Code Sharing Strategy --> Portable Class Library (PCL)
6.2) SQLite Library - SQLite.Net-PCL by oystein krog, Frank Krueger, Tim Heuer

Available under NuGet Manager.


6.3) Android Project Settings:
  • Minimum android version : Android 4.0.3 (API Level 15 - Ice cream Sandwich)
  • Target android version : Compile using SDK version
7.) Instructions:
  1. Download the sample code.
  2. Unzip the file
  3. Open the Visual Studio Solution file : PCL_DB_Pub.sln.

    Make sure you have Visual Studio 2015 or higher.

  4. Project references
    1. Take note that the references files (project library) was included in the zip file due to its size.

      However, Visual Studio should be able to automatically restore the references when the projects are first loaded - make sure the Internet connection is stable.

    2. Optional

      In case Visual Studio fail to automatically restore the refences, you will have to do it manually.

      To restore the references for both portable and Android project, make use of NuGet Manager.

      Copy and backup the content of the packages.config file into notepad for both Portable and Android project.

      Save the notepad files.

      Clear the content of packages.config file for both Portable and Android project - maintain the root element - save the changes.

      Copy and backup the packages list of packages.config

      Clear the packages list and save the file
      Make use of NuGet Manager to search each library reference listed under packages.config file --> refer to the backup content in the notepad files.

      Install each library reference using NuGet Manager, make sure you select the proper version - it will help you to install dependencies as well.

  5. Once you have restored all references - which include the reference for SQLite.Net-PCL - build the project.
  6. Simulate the app using an Android Emulator.

    The sample app whilst running in an Android Emulator
Video Tutorial:



Comments