Пример #1
0
        public static SongsDTO getSongByID(int id)
        {
            using (SqlConnection conn = new SqlConnection(connString))
            {
                try
                {
                    conn.Open();

                    String        sqlQuery = String.Format("Select * from Songs where SongID = {0}", id);
                    SqlCommand    comm     = new SqlCommand(sqlQuery, conn);
                    SqlDataReader reader   = comm.ExecuteReader();

                    SongsDTO dto = new SongsDTO();

                    if (reader.Read() == true)
                    {
                        dto.SongID = reader.GetInt32(0);
                        dto.Name   = reader.GetString(1);
                        dto.Singer = reader.GetString(2);
                        dto.Link   = reader.GetString(3);
                    }

                    return(dto);
                }
                catch (Exception ex)
                {
                    return(null);
                }
            }
        }
Пример #2
0
        public static List <SongsDTO> getAllSongs()
        {
            using (SqlConnection conn = new SqlConnection(connString))
            {
                try
                {
                    conn.Open();

                    String        sqlQuery = String.Format("Select * from Songs");
                    SqlCommand    comm     = new SqlCommand(sqlQuery, conn);
                    SqlDataReader reader   = comm.ExecuteReader();

                    List <SongsDTO> list = new List <SongsDTO>();

                    while (reader.Read() == true)
                    {
                        SongsDTO dto = new SongsDTO();
                        dto.SongID = reader.GetInt32(0);
                        dto.Name   = reader.GetString(1);
                        dto.Singer = reader.GetString(2);
                        dto.Link   = reader.GetString(3);

                        list.Add(dto);
                    }

                    return(list);
                }
                catch (Exception ex)
                {
                    return(null);
                }
            }
        }