ADO Net Database ASP.Net Tutorial

using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
public class ProductDataReader
{
    private readonly string _conString;
    public SqlDataReader GetProducts()
    {
        SqlConnection con = new SqlConnection(_conString);
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandText = "SELECT Id,Title,Director FROM Products";
        con.Open();
        return cmd.ExecuteReader(CommandBehavior.CloseConnection);
    }
    public ProductDataReader()
    {
        _conString = WebConfigurationManager.ConnectionStrings["Products"]. ConnectionString;
    }
}
            
File: index.aspx
<%@ Page Language="C#" %>
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">


    Show Product DataReader


    
    

            id="grdProducts"
        DataSourceID="srcProducts"
        Runat="server" />
            id="srcProducts"
        TypeName="ProductDataReader"
        SelectMethod="GetProducts"
        Runat="server" />
    

    


File: Web.config

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