Preferred Language:
Listing 16.40 - MovieDataSource.cs
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Web.UI.WebControls;
namespace AspNetUnleashed.Samples
{
public class MovieDataSource : ObjectDataSource
{
public MovieDataSource()
{
this.TypeName = "AspNetUnleashed.Samples.MoviesComponent";
this.SelectMethod = "GetMovies";
}
}
public class MoviesComponent
{
private readonly string _conString;
public SqlDataReader GetMovies()
{
// Initialize connection
SqlConnection con = new SqlConnection(_conString);
// Initialize command
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "SELECT Title,Director,DateReleased FROM Movies";
// Execute command
con.Open();
return cmd.ExecuteReader(CommandBehavior.CloseConnection);
}
public MoviesComponent()
{
_conString = 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.