You have the choice between using an hibernation layer like NHibernation or the bettwer EntityFramework from Microsoft, or, you have to do it manually. If this is the way, you have to create a Movie object like this:
public class Movie
{
public string MovieID { get; set; }
public string MovieName { get; set; }
public string MovieLength { get; set; }
public string MovieDesc { get; set; }
}
Then you can read the database query into a reader and fill the objects into a list, like this:
List<Movie> listOfMovies = new List<Movie>();
using(SqlConnection connection = new SqlConnection("Data Source=balder.ucn.dk;Initial Catalog=dmaa0213_6;********"))
{
using(SqlCommand cmd = new SqlCommand(connection))
{
cmd.CommandString = "SELECT * FROM movies ORDER BY MovieId";
connection.Open();
using(SqlDataReader reader = cmd.ExecuteDataReader())
{
while(reader.Read())
{
Movie item = new Movie();
item.MovieId = reader.GetInt32(0);
item.MovieName = reader.GetString(1);
item.MovieLength = reader.GetString(2);
item.MovieDesc = reader.GetString(3);
listOfMovies.Add(item);
}
}
connection.Close();
}
}