Skip to content

Instantly share code, notes, and snippets.

@smetronic
Created March 29, 2018 09:43
Show Gist options
  • Save smetronic/ce02fa65bdc6fae798a0f0197be0a149 to your computer and use it in GitHub Desktop.
Save smetronic/ce02fa65bdc6fae798a0f0197be0a149 to your computer and use it in GitHub Desktop.
Retrieving data from database using SQLITE SqlDataReader
public List<Primary> GetAll()
{
var primaryList = new List<Primary>();
using (SQLiteConnection conn = new SQLiteConnection("Data Source=data.db;Version=3;"))
{
conn.Open();
string sql = "SELECT * FROM PrimaryReader";
using (SQLiteCommand cmd = new SQLiteCommand(sql, conn))
{
SQLiteDataReader reader = cmd.ExecuteReader();
{
while (reader.Read())
{
primaryList.Add(new Primary()
{
Id = int.Parse(reader["Id"].ToString()),
Label = reader["Label"].ToString(),
Flag = int.Parse(reader["Flag"].ToString()),
Timestamp = DateTime.Parse(reader["Timestamp"].ToString())
});
}
}
}
}
return primaryList;
}
public class Primary
{
public int Id { get; set; }
public string Label { get; set; }
public int Flag { get; set; }
public DateTime Timestamp{ get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment