ADO Database ASP.Net

File: ProductsByCategory.cs
using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
public class ProductsByCategory
{
    private readonly string _conString;
    private readonly string _ProductCategory;
    public SqlDataReader GetProducts()
    {
        SqlConnection con = new SqlConnection(_conString);
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandText = "SELECT Title,Director,DateReleased FROM Products"
            + " JOIN ProductCategories ON Products.CategoryId=ProductCategories.Id"
            + " WHERE ProductCategories.Name=@CategoryName";
        cmd.Parameters.AddWithValue("@CategoryName", _ProductCategory);
        con.Open();
        return cmd.ExecuteReader(CommandBehavior.CloseConnection);
    }
    public ProductsByCategory(string ProductCategory)
    {
        _ProductCategory = ProductCategory;
        _conString = WebConfigurationManager.ConnectionStrings["Products"]. ConnectionString;
    }
}
File: Web.config

  
             connectionString="Data Source=.\SQLEXPRESS;
         AttachDbFilename=|DataDirectory|MyDatabase.mdf;Integrated Security=True;User Instance=True" />
  


File: Default.aspx
<%@ Page Language="C#" %>
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

    protected void srcProducts_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
    {
        ProductsByCategory Products = new ProductsByCategory("Adventure");
        e.ObjectInstance = Products;
    }



    Adventure Products


    
            id="grdProducts"
        DataSourceID="srcProducts"
        Runat="server" />
            id="srcProducts"
        TypeName="ProductsByCategory"
        SelectMethod="GetProducts"
        OnObjectCreating="srcProducts_ObjectCreating"
        Runat="server" />