public List <TvSerie> GetAllTvSeries() { using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand("Select * FROM TvSerie", connection); connection.Open(); List <TvSerie> tvSerieList = new List <TvSerie>(); var reader = cmd.ExecuteReader(); while (reader.Read()) { TvSerie t = new TvSerie { ItemID = reader.GetInt32(0), ItemName = reader.GetString(1), Picture = reader.GetString(2), Genre = reader.GetString(3), Seasons = reader.GetInt32(4), EpisodeLength = reader.GetInt32(5) }; tvSerieList.Add(t); } return(tvSerieList); } }
public TvSerie GetTvSerieByID(int id) { using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand("Select * From [dbo].[TvSerie] WHERE id = @id", connection); connection.Open(); cmd.Parameters.AddWithValue("id", id); var reader = cmd.ExecuteReader(); TvSerie tvSerie = new TvSerie(); while (reader.Read()) { tvSerie = new TvSerie() { ItemID = reader.GetInt32(0), ItemName = reader.GetString(1), Picture = reader.GetString(2), Genre = reader.GetString(3), Seasons = reader.GetInt32(4), EpisodeLength = reader.GetInt32(5) }; } return(tvSerie); }; }