public static Photos GetPhoto(int id) { string conString = WebConfigurationManager.ConnectionStrings["FrozenCrittersDb"].ConnectionString; SqlConnection con = new SqlConnection(conString); SqlCommand getPhoto = new SqlCommand(); getPhoto.CommandText = "SELECT PhotosId, PhotosFile, PhotosName, PhotosDescription FROM Photos WHERE PhotosId = " + id; getPhoto.Connection = con; con.Open(); SqlDataReader reader = getPhoto.ExecuteReader(); Photos photo = new Photos(); while (reader.Read()) { photo.PhotosId = (int)reader["PhotosId"]; photo.PhotosFile = reader["PhotosFile"].ToString(); photo.PhotosName = reader["PhotosName"].ToString(); photo.PhotosDescription = reader["PhotosDescription"].ToString(); } con.Close(); return(photo); }
public static List <Photos> GetAllPhotos() { string conString = WebConfigurationManager.ConnectionStrings["FrozenCrittersDb"].ConnectionString; SqlConnection con = new SqlConnection(conString); SqlCommand getPhotos = new SqlCommand(); getPhotos.CommandText = "SELECT PhotosId, PhotosFile, PhotosName, PhotosDescription FROM Photos"; getPhotos.Connection = con; con.Open(); SqlDataReader reader = getPhotos.ExecuteReader(); var photos = new List <Photos>(); while (reader.Read()) { Photos photo = new Photos(); photo.PhotosId = (int)reader["PhotosId"]; photo.PhotosFile = reader["PhotosFile"].ToString(); photo.PhotosName = reader["PhotosName"].ToString(); photo.PhotosDescription = reader["PhotosDescription"].ToString(); photos.Add(photo); } con.Close(); return(photos); }