Preferred Language:
Listing 17.15 - App_Code\Movie5.cs
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Collections.Generic;
public class Movie5
{
private static readonly string _connectionString;
private string _title;
private decimal _boxOfficeTotals;
public string Title
{
get { return _title; }
set { _title = value; }
}
public decimal BoxOfficeTotals
{
get { return _boxOfficeTotals; }
set { _boxOfficeTotals = value; }
}
public List<Movie5> GetBoxOffice(out decimal SumBoxOfficeTotals)
{
List<Movie5> results = new List<Movie5>();
SqlConnection con = new SqlConnection(_connectionString);
SqlCommand cmd = new SqlCommand("GetBoxOfficeTotals", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@SumBoxOfficeTotals", SqlDbType.Money).Direction = ParameterDirection.Output;
using (con)
{
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
Movie5 newMovie = new Movie5();
newMovie.Title = (string)reader["Title"];
newMovie.BoxOfficeTotals = (decimal)reader["BoxOfficeTotals"];
results.Add(newMovie);
}
reader.Close();
SumBoxOfficeTotals = (decimal)cmd.Parameters["@SumBoxOfficeTotals"].Value;
}
return results;
}
static Movie5()
{
_connectionString = WebConfigurationManager.ConnectionStrings["Movies"].ConnectionString;
}
}
ASP.NET 3.5 Unleashed
- Containing almost 2,000 pages of code samples and in-depth explanation of the
ASP.NET 3.5 Framework, ASP.NET 3.5 Unleashed is the most comprehensive book
written on the ASP.NET 3.5 Framework.
ASP.NET 3.5 Unleashed is now available in your local bookstore and online (Published January 7, 2008).
All of the code samples from this book are hosted "live" at this website.
Click here
to view the table of contents and code samples.