1

What is the best way to populate a List using a SQLite DB. I had been using SQLiteDataAdapter and one of a colleague of mine told me that it is not a great choice.

Doro
  • 671
  • 1
  • 16
  • 34

1 Answers1

2

You could use a SqliteDataReader.

 using(SqliteConnection con = new SqliteConnection(cs))
        {
            con.Open();

            string stm = "SELECT ListItem FROM Table";

            using (SqliteCommand cmd = new SqliteCommand(stm, con))
            {
                using (SqliteDataReader rdr = cmd.ExecuteReader())
                {
                    while (rdr.Read()) 
                    {
                        //add items to your list
                    }         
                }
            }

            con.Close();   
         }

From this article.

The SqliteDataReader is a class used to retrieve data from the database. It is used with the SqliteCommand class to execute an SQL SELECT statement and then access the returned rows. It provides fast, forward-only, read-only access to query results. It is the most efficient way to retrieve data from tables.

This comparison is for SQL Server, but the result is the same: SqlDataAdapter vs SqlDataReader

Another comparison chart here from this article.

enter image description here

Community
  • 1
  • 1
Christian Phillips
  • 18,399
  • 8
  • 53
  • 82