1. Create a stored procedure in database
    After expanding the database follow this:
    Programmability>Stored Procedures>Right click on it and select New Stored Procedure
    Here write codes to create a procedure. I created a simple procedure like following:
    My procedure’s name is GetProducts which will take a parameter named pricerange of type int.
    Click Execute  button on the top and the procedure will be created.
    To test the procedure I executed it like this:
    I passed the price range value 20 and the command returned all the products having price value below  20.
  2. Create a class for storing the resultFor holding the result value I created a result class like this in model folder:
  3. Call the procedure from controllerI wrote a simple controller function like this:
    ProjectDbContext is my DbContext class. priceRangeParam is to take my sql parameter. GetProducts is the procedure name created in sql database. The result will be treated as object of my ResultForProduct class which will take only the price value of the returned data. I passed it to view through viewbag and showed it like this:

    That’s it! 🙂

(Visited 34 times, 1 visits today)

14 thoughts on "Sql server stored procedure using Asp.net MVC code first"

  1. Khaza says:

    good writing

  2. jobs says:

    Hi everyone, it’s my first pay a visit at this web page, and piece of writing is really fruitful in favor of me, keep up posting these articles or reviews.

  3. Howdy! I’m at work browsing your blog from my new apple iphone! Just wanted to say I love reading through your blog and look forward to all your posts! Carry on the superb work!

  4. Attractive section of content. I just stumbled upon your website and in accession capital to assert that I get in fact enjoyed account your blog posts. Any way I’ll be subscribing to your feeds and even I achievement you access consistently quickly.

  5. For most recent news you have to pay a visit internet and on web I found this web page as a finest web page for newest updates.

  6. It’s fantastic that you are getting thoughts from this article as well as from our discussion made at this place.

  7. Very descriptive blog, I loved that a lot. Will there be a part 2?

  8. I’m amazed, I have to admit. Rarely do I encounter a blog that’s both educative and engaging, and let me tell you, you’ve hit the nail on the head. The problem is something too few folks are speaking intelligently about. I am very happy I stumbled across this in my search for something concerning this.

  9. Hello, i think that i saw you visited my website thus i came to “return the favor”.I’m attempting to find things to improve my site!I suppose its ok to use some of your ideas!!

  10. Keep this going please, great job!

  11. Hi, I wish for to subscribe for this web site to take newest updates, therefore where can i do it please help out.

  12. I’d like to thank you for the efforts you have put in penning this blog. I am hoping to see the same high-grade blog posts by you in the future as well. In fact, your creative writing abilities has motivated me to get my own website now 😉

  13. Hello! Do you know if they make any plugins to assist with Search Engine Optimization? I’m trying to get my blog to rank for some targeted keywords but I’m not seeing very good gains. If you know of any please share. Kudos!

  14. I simply want to tell you that I am just beginner to blogging and truly liked your web blog. Most likely I’m going to bookmark your blog post . You definitely have good writings. Many thanks for sharing your web site.

Leave a Reply

Your email address will not be published. Required fields are marked *