Open4

SQLiteをC#で操作する

Takayuki KondoTakayuki Kondo

Microsoft.Data.Sqlite は SQLite の軽量 ADO.NET プロバイダーのこと。
https://learn.microsoft.com/ja-jp/dotnet/standard/data/sqlite/

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}!");
        }
    }
}