Handout 3

Handout 3 - Once you have bound your database table to a...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
IS 3920 - Application Development II Handout #3 Using SQL Server Express Databases with MVC Visual Studio gives you many ways to connect a Database to your project as a Data source. In this class, we will be using the SQL Server Express Database that is automatically installed as a service when you install Visual Studio. To create your SQL Database you must choose “SQL Server Database” when you add a new Data source. You can see your Database in the App_Data folder in your Solution Explorer, or in the Server Explorer Data Connections: When you have created your database, you add a new Table and all of your table fields through the Server Explorer. You can also view and edit your Table data through the Server Explorer When you create a Model for your MVC project, you can use one that is based on the fields of your Database Table. You do this by choosing the: ADO.NET Entity Data Model template
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Once you have bound your database table to a model, the model class is called an Entity and the Entity gives you access to the Table and to the different records in the table: WebAccounts => Dabase name WebAccountsEntities => Model Class name for WebAccounts Accounts => Table object in the WebAccountsEntities class Account => Class name of Record in Accounts table To access table data in a Controller function you do the following: Byval db As New WebAccountsEntities Creates a new Model for the Database ByVal accountrecord As New Account Creates a new Account record accountrecord.Fullname = "John Smith" Fills in a field in the Account record db.AddToAccounts(accountrecord) Adds the Account record to the Accounts table Return View(db.Accounts) Returns the table data in the Model to a view 1 of 1...
View Full Document

Ask a homework question - tutors are online