File: App_Code\Product.cs
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Collections.Generic;
public class Product
{
private static readonly string _connectionString;
public DataTable GetAll()
{
SqlDataAdapter dad = new SqlDataAdapter("SELECT Title,Director FROM Products", _connectionString);
DataTable dtblProducts = new DataTable();
dad.Fill(dtblProducts);
return dtblProducts;
}
static Product()
{
_connectionString = WebConfigurationManager.ConnectionStrings["Products"].ConnectionString;
}
}
File: Web.config
connectionString="Data Source=.\SQLEXPRESS;
AttachDbFilename=|DataDirectory|MyDatabase.mdf;Integrated Security=True;User Instance=True" />
File: ShowProduct.aspx
<%@ Page Language="C#" %>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Show Product