[英]How do you create an SQLite Database with c# in Visual Studio?
I am creating an SQLite
Database in Visual Studio
with Xamarin
in C#
. 我正在使用
C#
Xamarin
在Visual Studio
创建一个SQLite
数据库。
I should note that this is for android
only. 我应该注意,这只适用于
android
。
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. 据我所知,在这个类中我必须创建
SQLite
数据库,并使其能够添加,删除和检索数据。
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.
}
}
}
The SQLite Component has pretty clear documentation - is there something specific you don't understand? SQLite组件有非常清晰的文档 - 有什么特定的东西你不明白吗?
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.