📜  c# sqlite 查询 - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:22.140000             🧑  作者: Mango

代码示例1
public List GetUsers()
{
    // Init return list
    List users = new List();

    // Set the path to sqlite file
    string solutionPath = Environment.CurrentDirectory;
    string dbPath = Path.Combine(solutionPath, "db.sqlite3");    

    SQLiteConnection connection = new SQLiteConnection(solutionPath);
    connect.Open();

    // Construct sql query
    SQLiteCommand command = connection.CreateCommand();
    command.CommandText = @"SELECT username FROM tableUsers";
    command.CommandType = CommandType.Text;

    SQLiteDataReader reader = command.ExecuteReader();

    // reader is treated like a array so call 
    while (reader.Read())
        users.Add(Convert.ToString(reader["username"]));

    // Clean up no longer needed connection
    connection.Close();

    return users;
}