How to use sql server 2005 stored procedures in asp.net mvc? -
I just started a new web application with asp.net mvc
and sql server Done 2005
... so far in my webform applications i used ADO.NET
... I am in my asp.net MVC
aplication only I want to ...
I have a database with all the stored procedures
in sql server 2005
... now I use my stored procedures In your MVC application Want to ..I will not use any ORM
... I do ADO I want to use Net
Any sample controller
which calls a model
using the stored procedure
And returns dataset
to controller
and then to see the controller
to show records ... any suggestions ...
I use a service or a repository, Responsible for creating the controller sends the scene. Ado me With the desire to use the net, the logic of avoiding the ORM is not convincing. Reality unit structure, Linq2Sql, subsonic, and NHibernate are very proven and reliable.
Here's a quick sample that I put together ... It uses SQL connections and SQL command to call stored functioning ... Put this code in a different category which That tells the controller to get the model.
Public BlogEntry GetBlogEntry (int blogId) {SqlConnection sqlConnection = New SqlConnection (); SqlConnection.ConnectionString = MyConnectionString; SqlCommand sqlCommand = New SqlCommand (); SqlCommand.CommandText = "mySproc"; SqlCommand.Connection = sqlConnection; SqlConnection.Open (); Var Reader = sqlCommand.ExecuteReader (); Var blogEntry = New BlogEntry (); While (reader.Read ()) // Do something to fill your model ...} return blogEntry; }
Comments
Post a Comment