Я создаю базу данных SQLite
в Visual Studio
с Xamarin
в C#
.Вставка данных в базу данных SQLite с использованием C#
Следует отметить, что это только для android
.
Я пытаюсь сделать так, чтобы я мог вставлять данные в базу данных SQLite
, но я не уверен, как это сделать.
Я слежу this, но я все еще не уверен.
Вот метод, который я пытаюсь создать.
/// <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.
if (pingGroup != null)
{
// Add ping group to the database.
// Add pings to the database.
// Maybe one step, maybe done separately.
// If done separately, must set Ping.PingGroupID to ID of original ping group.
}
}
Для контекста здесь представлен весь класс.
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
{
private SQLiteConnection db = null;
public DataManager()
{
if (this.db == null)
{
string dbPath = Path.Combine(
System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal),
"bb.db3");
db = new SQLiteConnection(dbPath);
db.CreateTable<Ping>();
db.CreateTable<PingGroup>();
}
}
/// <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.
//var pGroup = db.Get<PingGroup>();
//var pGroupList = db.List<PingGroup>();
var pGroups = db.Table<PingGroup>();
foreach (var pGroup in pGroups)
{
}
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.
if (pingGroup != null)
{
// Add ping group to the database.
// Add pings to the database.
// Maybe one step, maybe done separately.
// If done separately, must set Ping.PingGroupID to ID of original ping group.
}
}
/// <summary>
/// Mark all open and unsynchronized pings in the database as synchronized.
/// </summary>
public void SetAllPingsSynchronized()
{
db.DeleteAll<PingGroup>();
db.DeleteAll<Ping>();
}
}
}
Заранее спасибо.