Reputation: 65
I am creating an SQLite
Database in Visual Studio
with Xamarin
in C#
.
I should note that this is for android
only.
From what I understand, in this class I must create the SQLite
Database, and make it so I am able to add, delete, and retrieve data.
I should also note that there is a separate class to call the methods in this class.
I am very new to this and I am not sure how to do this.
I've read tutorials, I've watched hour long videos, and I still am not able to figure out this.
Any help would be greatly appreciated.
This is the class template I am using and must follow:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using BB.Mobile.Models;
namespace BB.Mobile
{
/// <summary>
/// A class to provide a single interface for interacting with all SQLite data operations for stored tracking points.
/// </summary>
class DataManager
{
/// <summary>
/// Will compile and return all matching unsynchronized ping data from the SQLite database.
/// </summary>
/// <returns></returns>
public List<PingGroup> GetUnsynchronizedPings()
{
List<PingGroup> unsynchronizedPings = new List<PingGroup>();
// TODO: Retrieve all unsynchronized pings from the SQLite database and return them to the caller.
return unsynchronizedPings;
}
/// <summary>
/// Insert a single ping group into the SQLite ping database.
/// </summary>
/// <param name="pingGroup"></param>
public void AddUnsynchronizedPing(PingGroup pingGroup)
{
// TODO: Add the passed ping group parameter into the SQLite database as new/unsynchronized.
}
/// <summary>
/// Mark all open and unsynchronized pings in the database as synchronized.
/// </summary>
public void SetAllPingsSynchronized()
{
// TODO: Delete all database data or set it as synchronized using a flag.
}
}
}
Upvotes: 4
Views: 5365
Reputation: 89082
The SQLite Component has pretty clear documentation - is there something specific you don't understand?
using SQLite;
// ...
public class Note
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string Message { get; set; }
}
// Create our connection
string folder = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
var db = new SQLiteConnection (System.IO.Path.Combine (folder, "notes.db"));
db.CreateTable<Note>();
// Insert note into the database
var note = new Note { Message = "Test Note" };
db.Insert (note);
Upvotes: 2