To add more flexibility to DamithSL's solution, consider this:
public class Book
{
public string Title { get; private set; }
public string Author { get; private set; }
public string Isbn { get; private set; }
public Book ( System.Data.IDataRecord Data )
{
Title = (string) Data [ 0 ] ;
Author = (string) Data [ 1 ] ;
Isbn = (string) Data [ 2 ] ;
}
}
public List<Book> Select(string query)
{
List<Book> books = new List<Book>();
if (this.OpenConnection() )
{
using ( SQLiteCommand cmd = new SQLiteCommand(query, con) )
{
using ( SQLiteDataReader dataReader = cmd.ExecuteReader() )
{
while (dataReader.Read())
{
books.Add ( new Book ( dataReader ) ) ;
}
}
}
this.CloseConnection();
}
return books;
}
There may be a way to make it generic, but it escapes me at the moment.