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;
}
}
Need ASP.NET and Visual Studio 2008 Training?
- Learn ASP.NET 3.5 from Stephen Walther, author of ASP.NET 3.5 Unleashed.
We've provided ASP.NET training for NASA, Lockheed Martin, the National Science Foundation, Verizon,
Boeing, the US House of Representatives, Kaiser, Petco, Mary Kay, and Microsoft.
Why not your company?
-
Receive a four day, hands-on, intensive workshop.
-
We fly to you, anywhere in the world.
-
We can bring our own laptops.
To learn more, visit the
Superexpert Training website.