简体   繁体   中英

Access SQLite Data and Display it in DataGridView in C#

as new to C# and SQLite world, how can i possibly display data from SQLite in the DataGridView in C#? I really don't have any idea on how to do it. Even I tried some tutorials from the internet but I don't get it right. And most of them are using MySQL.

  1. You can use System.Data.SQLite ADO.NET provider for connecting to your sqlite db.

When the references are added, you can write queries, like

using (var conn = new SQLiteConnection(@"Data Source=test.db3"))
using (var cmd = conn.CreateCommand())
{
    conn.Open();
    cmd.CommandText = "SELECT * FROM random_table_name";
    using (var reader = cmd.ExecuteReader())
    {
        while (reader.Read())
        {
            string name = reader.GetString(reader.GetOrdinal("name"));
            ...
        }
    }
}
  1. Put the read values into a List or some kind of collection.
  2. After finishing, you can bind your Data Grid View into your list. It's a good msdn page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM