Asp.Net MVC: With Product example 1
Web.config - Add the connection string <connectionStrings> <add name="ProductDBConnectionString" connectionString="Data Source=LK-PRK\SQL2012DEV;Initial Catalog=ProductDB;Integrated Security=True" providerName="System.Data.SqlClient" /> </connectionStrings> Connections.cs - in Model section using System.Configuration; using System.Data.SqlClient; namespace TestStock.Models { public class Connection { public static SqlConnection GetConnection() { var conn = ConfigurationManager.ConnectionStrings["ProductDBConnectionString"].ConnectionString; return new SqlConnection(conn); } } } Products.cs - in Models section namespace TestStock.Models { public class Product ...