Created
March 29, 2018 09:43
-
-
Save smetronic/ce02fa65bdc6fae798a0f0197be0a149 to your computer and use it in GitHub Desktop.
Retrieving data from database using SQLITE SqlDataReader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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