MVC 3 and Stored Procedure – part 1

When I looking for the tutorial about MVC 3, about connect and work with database. The examples or the tutorials are about MVC 3 and LINQ but the thing I want is MVC3 and Stored Procedure. So I’ve decided to write examples about MVC3 – Stored Procedure and It’s work. And I want to share it for the users who get to known the Stored Procedure as well.

First you have to download this Dataprovider.cs to work with this tutorial and add it in DAO folder
http://www.mediafire.com/download.php?2gko1ryc78ogoch

This tutorial is about Manage Students.

First part, I will show you the prepare for this tutorial and get list students.

I. Prepare for tutorial

1. Database


2. Add Connection


3. Add Class StudentDTO and declare variables

4. Add Class ClassDTO and declare variables

II. Get List Student

1. Write Stored Procedure


In this store, I joined two table Student and Class to get: StuID, Name, BirthYear, ClassID, ClassName. Of course you can select whatever you want.

2. Write Function GetListStudent

First: Go to Folder Models -> Folder DAO -> StudentDAO.cs




In the image above, I wrote the function execute the stored procedure and returns the List of Student.

3. Write Function in Controller

First: you have to add the Controller. In this tutorial I added Controller name “HomeController.cs”
Now I am going to get the value which return the list of student from StudentDAO.cs


4. Add View and Test

Because the fields of StudentDTO.cs get the value from the stored procedure. So I add view and choose Model Class StudentDTO.cs

Compile the the solution and run


Stay tuned for next part.

2 thoughts on “MVC 3 and Stored Procedure – part 1

  1. Hello,
    I find your tutorials very clear and beneficial. I wonder if this is still up to date with MVC5 better practice workign with sProcs. I am a newbie trying to follow the best coding practice possible.
    Thank you very much!
    Harold

Leave a comment