MVC database
ASP.NET MVC - SQL Database
To learn ASP.NET MVC, we will build an Internet application.
Part 6: Add the database.
Create Database
Visual Web Developer comes with a free SQL database called SQL Server Compact.
The database required for this tutorial can be created by following a few simple steps:
Right-click Solution Explorer in the window ##App_Data Folder
##Select- Add, New Item
- SQL Server Compact Local Database *
- Movies.sdf
- Add
Button
If there is no SQL Server Compact Local Database in the options, you have not installed SQL Server Compac on your computer. Please install via the following link: SQL Server CompactVisual Web Developer automatically creates the database in the App_Data folder.
Note:In this tutorial, you need to master some basic knowledge about SQL database. If you want to learn this topic first, visit our SQL tutorial.
Add database tableDouble-click the
Movies.sdffile in the App_Data folder and Database Explorer## will open # window. To create a new table in the database, right-click the Tables
folder and selectCreate Table. Create the following columns:
##ColumnWhether Null is allowed | ID | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
No | ##Title | nvarchar(100) | |||||||||||
Director | nvarchar(100) | ||||||||||||
Date | datetime | ||||||||||||
ID | Title | Director | Date |
---|---|---|---|
1 | Psycho | Alfred Hitchcock | 01.01.1960 |
2 | La Dolce Vita | Federico Fellini | 01.01.1960 |
##Note: ID column will automatically Update, you don't have to edit it.
Add connection stringsAdd the following elements to the
<connectionStrings> element in your Web.config file:
providerName="System.Data.SqlServerCe.4.0"/>