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 App_Data in the Solution Explorer window Folder
- SelectAdd, New Item
- SelectSQL Server Compact Local Database *
- Name the database Click the Add button for Movies.sdf
* 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 Compact
Visual 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, please visit our SQL Tutorial.
Add database table
Double-click the Movies.sdf file in the App_Data folder and Database Explorer## will open # window.
To create a new table in the database, right-click theTables folder and select Create Table.
Create the following columns:Type | Whether Null is allowed | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
int (primary key) | No | ##Title | ||||||||||||
No | Director | |||||||||||||
No | Date | |||||||||||||
No |
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"/>