且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从 C# 连接和使用 sqlite 数据库的***方法是什么?

更新时间:2023-02-09 15:55:58

Microsoft.DataMicrosoft 的 .Sqlite 每天有超过 9000 次下载,所以我认为您可以安全地使用它.

Microsoft.Data.Sqlite by Microsoft has over 9000 downloads every day, so I think you are safe using that one.

来自文档的示例用法:

using (var connection = new SqliteConnection("Data Source=hello.db"))
{
    connection.Open();

    var command = connection.CreateCommand();
    command.CommandText =
    @"
        SELECT name
        FROM user
        WHERE id = $id
    ";
    command.Parameters.AddWithValue("$id", id);

    using (var reader = command.ExecuteReader())
    {
        while (reader.Read())
        {
            var name = reader.GetString(0);

            Console.WriteLine($"Hello, {name}!");
        }
    }
}