SIGN UP MEMBER LOGIN:    
ARTICLE

Create database dynamically using MVC ASP.NET application

Posted by Manish Singh Articles | ASP.NET MVC with C# November 26, 2011
This is the simple application using ASP. NET MVC tools. This is for beginners how to create a database in a MVC application.
Reader Level:

Introduction : This is a simple application using ASP.NET MVC tools. This is for beginners how to create a database in a MVC application. The ASP.NET MVC framework supports using any data access technology, and developers can choose from a variety of rich .NET data options to implement their models including: LINQ to Entities, LINQ to SQL, NHibernate, LLBLGen Pro, SubSonic, WilsonORM, or just raw ADO.NET DataReaders or Datasets. If you developed any information based project first need is manage information in database. ASP.NET MVC provide some tools that used add the data base in your application easily. This is a very simple program I hope it's very helpful  for beginners and solve the problem how to create database in a MVC application.

Step 1 :

  • Open Visual Studio 2010.
  • Click file ->New->Projects.
  • Add MVC ASP. NET 2 Empty Web application.

start.gif

Step 2 : Next step add one folder in Solution Explorer.

  • Right Click of Solution Explorer add a Folder.
  • Right Click of Solution Explorer->Add->Folder.
  • Name of folder "App_Data".

appfolder.gif

Step 3: In a App_Data folder  add LINQ to SQL CLASS. LINQ to SQL will then takes care of generating the appropriate SQL execution logic to use at runtime when we interact and use them.

  • Right Click of App_Data Folder->Add New Item-> add "LINQ to SQL" class.

linq-class.gif

Step 4 : After add the LINQ to SQL class two file create in folder.

  • First is "Database1.mdf".
  • Second is "Database_log.ldf".

Step 5 : Open the Server Explorer.

  • Right Click of "Database1.mdf"->Add Table Schema.
  • Set the fields "ID,FName,LName,Address,Salary".

open-solution-exfloree.gif

mdf-file.gif

tableshema.gif

Step 6: If you want to set the Primary key and Relationship.

  • Right click of "ID" Fields and set Primary key.
  • In same way set Relationship.
  • Close and Save the name of the table Just like a "Person".
saverecor.gif
set-primary-key.gif

relationship.gif

Step 7 : Click the table.

  • Right click of Person and open "Show table data".
  • Insert data from a table.
enter-table-records.gif

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor