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.

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the answer. Do you know why it is not that great?
@doro, I just added a comparison to the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.