如何在Visual Studio中使用C#创建SQLite数据库?

4

我正在使用XamarinVisual Studio中以C#创建一个SQLite数据库。

需要注意的是,这仅适用于Android操作系统。

据我所知,在这个类中,我必须创建SQLite数据库,并使其能够添加、删除和检索数据。

还需要注意的是,有一个单独的类来调用此类中的方法。

我非常新手,不确定如何做到这一点。

我已经阅读了教程,观看了长达一个小时的视频,但仍然无法弄清楚。

任何帮助都将不胜感激。

这是我正在使用并必须遵循的类模板:

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.

    }
}
}

你读过这个吗?http://erikej.blogspot.dk/2014/10/database-first-with-sqlite-in-universal.html - ErikEJ
1个回答

2
这里有一个很清晰的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);

嗨。我想问一下,我们是否可以保留创建文件的任何扩展名,或者它必须是fileName.db(即.db)。提前致谢。 - MindRoasterMir
1
我不认为扩展名有什么关系。 - Jason

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接