This article explains the following topic.
1. What are the essentials to look for connectiong to sqlite database in an app
2. Where does the sqlite database exists
3. what is the connection string
4. how to start wrting the code
1.Creating a Data Model to work with. For xeample below is the datamodel student.cs. This can be created in a seperate folder such as model folder or in the project node itself.
2. Create an interface in shared project folder
The following is the code.
In the above code we have included the dependency class of sqlitedatabase. We have used an attribute such as [assembly:Dependency(typeof(SqLiteDatabase))].
This referece to the installed sqlite instance. in the next line we have created a class by name sqliteconnection which derives from the isqlite interface and implements a Get connection method to get connection instance to the sqlite database.Next we have defined variables to hold the following:
var Dbase= name of the database
var dbpath=name of the database path where it resides on your android mobile. ususally this will be in the System.Environment.SpecialFolder.ApplicationData folder which we can get by using System.Environment.GetFolderpath enumerator of C#.
then var path=Path.combine(dbpath,dbase) combine the database and gives access to the complete path.
and the connection object will return the actual connection.
Now to consolidate the above activity Firstly we installed the Sqlite database, then Write an interface class with a method in the shared folder , then write a domain model class, then write a dataaccess class to implement the interface to get a connection access to sqlite database.
4. The next step will be to access this connection and make actual connection to the database , retrive the data and show it on a XAML form.
To this we need to design a XAML form. create a new XAML page and paste the following code:
The above code create a username and password form which will act as an entry point to the android app. the rendered XAML view might look as below