Accessing data with ADO.NET
Many apps need to use databases, irrespective of whether the app is database-centric or even just to store pieces of data in a structured form. Android provides SQLite as a database engine and .NET provides ADO.NET as an interface.
Getting ready...
This recipe demonstrates how we can make use of ADO.NET to interact with a SQLite database using SQL. It is assumed that you have some SQL knowledge to construct queries.
How to do it...
Using ADO.NET with SQLite is easy and not much different from working with any ADO.NET provider. It is fairly straightforward to create and interact with a SQLite database:
To start with, we need to add a reference to
System.Data
andMono.Data.SQLite
.We can now start selecting what database file we will use. If a database file does not exist, one will be created for us. To do this, we use a connection string:
var databasePath = Path.Combine(FilesDir.AbsolutePath, "database.sqlite"); var connectionString = string.Format("Data Source={0}",...